github.com/lastbackend/toolkit@v0.0.0-20241020043710-cafa37b95aad/interface.go (about)

     1  /*
     2  Copyright [2014] - [2023] The Last.Backend authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package toolkit
    18  
    19  import (
    20  	"context"
    21  	"github.com/lastbackend/toolkit/pkg/client"
    22  	"github.com/lastbackend/toolkit/pkg/runtime/logger"
    23  	"github.com/lastbackend/toolkit/pkg/runtime/meta"
    24  	"github.com/lastbackend/toolkit/pkg/server"
    25  )
    26  
    27  type Service interface {
    28  	Meta() *meta.Meta
    29  
    30  	Log() logger.Logger
    31  	Client() Client
    32  	Server() Server
    33  
    34  	RegisterConfig(config ...any) error
    35  	RegisterPlugin(constructor ...any)
    36  	RegisterPackage(constructor ...any)
    37  
    38  	Start(ctx context.Context) error
    39  	Stop(ctx context.Context, err error)
    40  
    41  	RegisterOnStartHook(...func(ctx context.Context) error)
    42  	RegisterOnStartSyncHook(...func(ctx context.Context) error)
    43  
    44  	RegisterOnStopHook(...func(ctx context.Context) error)
    45  	RegisterOnStopSyncHook(...func(ctx context.Context) error)
    46  }
    47  
    48  type Client interface {
    49  	GRPC() client.GRPCClient
    50  	HTTP() client.HTTPClient
    51  }
    52  
    53  type Server interface {
    54  	HTTP() server.HTTPServer
    55  	GRPC() server.GRPCServer
    56  
    57  	HTTPGet(name string) server.HTTPServer
    58  	HTTPNew(name string, options *server.HTTPServerOptions) server.HTTPServer
    59  
    60  	GRPCGet(name string) server.GRPCServer
    61  	GRPCNew(name string, options *server.GRPCServerOptions) server.GRPCServer
    62  }
    63  
    64  type Config any
    65  
    66  type Package any
    67  
    68  type PackageItem struct {
    69  	Index  int
    70  	Source any
    71  }
    72  
    73  type Plugin any