github.com/lastbackend/toolkit@v0.0.0-20241020043710-cafa37b95aad/pkg/runtime/interface.go (about) 1 package runtime 2 3 import ( 4 "context" 5 "github.com/caarlos0/env/v7" 6 "github.com/lastbackend/toolkit" 7 "github.com/lastbackend/toolkit/pkg/client" 8 "github.com/lastbackend/toolkit/pkg/runtime/logger" 9 "github.com/lastbackend/toolkit/pkg/runtime/meta" 10 "github.com/lastbackend/toolkit/pkg/server" 11 "github.com/lastbackend/toolkit/pkg/tools/metrics" 12 "github.com/lastbackend/toolkit/pkg/tools/probes" 13 "github.com/lastbackend/toolkit/pkg/tools/traces" 14 ) 15 16 type Runtime interface { 17 Meta() *meta.Meta 18 Log() logger.Logger 19 20 Client() Client 21 Package() Package 22 Server() Server 23 Config() Config 24 Plugin() Plugin 25 26 Tools() Tools 27 28 Service() toolkit.Service 29 30 Provide(constructor interface{}) 31 Invoke(constructor interface{}) 32 33 Start(ctx context.Context) error 34 Stop(ctx context.Context, err error) 35 36 RegisterOnStartHook(fn ...func(ctx context.Context) error) 37 RegisterOnStartSyncHook(fn ...func(ctx context.Context) error) 38 39 RegisterOnStopHook(fn ...func(ctx context.Context) error) 40 RegisterOnStopSyncHook(fn ...func(ctx context.Context) error) 41 } 42 43 type Client interface { 44 GRPC() client.GRPCClient 45 HTTP() client.HTTPClient 46 } 47 48 type HTTPClient interface { 49 Get() error 50 Post() error 51 } 52 53 type Server interface { 54 toolkit.Server 55 56 Start(ctx context.Context) error 57 Stop(ctx context.Context) error 58 59 HTTPList() map[string]server.HTTPServer 60 GRPCList() map[string]server.GRPCServer 61 62 Provides() []interface{} 63 Constructors() []interface{} 64 } 65 66 type Config interface { 67 Provide(...any) error 68 69 SetMeta(meta *meta.Meta) 70 Parse(v interface{}, prefix string, opts ...env.Options) error 71 Print(v interface{}, prefix string) 72 PrintTable(all, nocomments bool) string 73 PrintYaml(all, nocomments bool) string 74 75 Configs() []any 76 } 77 78 type Plugin interface { 79 Provide(constructor ...interface{}) 80 81 Constructors() []interface{} 82 Register(plugins []toolkit.Plugin) 83 84 PreStart(ctx context.Context) error 85 OnStart(ctx context.Context) error 86 OnStop(ctx context.Context) error 87 } 88 89 type Package interface { 90 Provide(constructor ...interface{}) 91 92 Constructors() []interface{} 93 Register(packages []toolkit.PackageItem) 94 95 PreStart(ctx context.Context) error 96 OnStart(ctx context.Context) error 97 OnStop(ctx context.Context) error 98 } 99 100 type Tools interface { 101 OnStart(ctx context.Context) error 102 103 Metrics() metrics.Metrics 104 Probes() probes.Probes 105 Traces() traces.Traces 106 }