package main import ( "context" "github.com/integration-system/isp-lib/backend" "github.com/integration-system/isp-lib/bootstrap" "github.com/integration-system/isp-lib/config/schema" "github.com/integration-system/isp-lib/logger" "github.com/integration-system/isp-lib/metric" "github.com/integration-system/isp-lib/structure" "google.golang.org/grpc" "isp-script-service/compile" "isp-script-service/conf" "isp-script-service/helper" "isp-script-service/router" "os" ) var ( version = "1.0.0" ) func main() { bootstrap. ServiceBootstrap(&conf.Configuration{}, &conf.RemoteConfig{}). OnLocalConfigLoad(onLocalConfigLoad). SocketConfiguration(socketConfiguration). DefaultRemoteConfigPath(schema.ResolveDefaultConfigPath("default_remote_config.json")). OnSocketErrorReceive(onRemoteErrorReceive). OnConfigErrorReceive(onRemoteConfigErrorReceive). DeclareMe(routesData). RequireModule("router", router.Client.ReceiveAddressList, true). OnRemoteConfigReceive(onRemoteConfigReceive). OnShutdown(onShutdown). Run() } func socketConfiguration(cfg interface{}) structure.SocketConfiguration { appConfig := cfg.(*conf.Configuration) return structure.SocketConfiguration{ Host: appConfig.ConfigServiceAddress.IP, Port: appConfig.ConfigServiceAddress.Port, Secure: false, UrlParams: map[string]string{ "module_name": appConfig.ModuleName, "instance_uuid": appConfig.InstanceUuid, }, } } func onShutdown(_ context.Context, _ os.Signal) { backend.StopGrpcServer() } func onRemoteConfigReceive(remoteConfig, oldRemoteConfig *conf.RemoteConfig) { compile.Script.Init(remoteConfig.Scripts) metric.InitCollectors(remoteConfig.Metrics, oldRemoteConfig.Metrics) metric.InitHttpServer(remoteConfig.Metrics) } func onLocalConfigLoad(cfg *conf.Configuration) { handlers := helper.GetAllHandlers() service := backend.GetDefaultService(cfg.ModuleName, handlers...) backend.StartBackendGrpcServer( cfg.GrpcInnerAddress, service, grpc.MaxRecvMsgSize(1024*1024*512), grpc.MaxSendMsgSize(1024*1024*512), ) } func routesData(localConfig interface{}) bootstrap.ModuleInfo { cfg := localConfig.(*conf.Configuration) return bootstrap.ModuleInfo{ ModuleName: cfg.ModuleName, ModuleVersion: version, GrpcOuterAddress: cfg.GrpcOuterAddress, Handlers: helper.GetAllHandlers(), } } func onRemoteErrorReceive(errorMessage map[string]interface{}) { logger.Warn(errorMessage) } func onRemoteConfigErrorReceive(errorMessage string) { logger.Error(errorMessage) }