init
This commit is contained in:
1 parent
bdbb3216ce
commit
c0775acb8a
25 files changed
+2252
No files matched your search
@@ -0,0 +1,79 @@
|
||||
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/structure"
|
||||
"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)
|
||||
}
|
||||
|
||||
func onLocalConfigLoad(cfg *conf.Configuration) {
|
||||
handlers := helper.GetAllHandlers()
|
||||
service := backend.GetDefaultService(cfg.ModuleName, handlers...)
|
||||
backend.StartBackendGrpcServer(cfg.GrpcInnerAddress, service)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
Reference in new issue
Block a user