engine/service/service.go

62 lines
1.8 KiB
Go
Raw Permalink Normal View History

2024-02-11 01:31:01 +08:00
package service
import (
"fmt"
"path/filepath"
"git.apinb.com/bsm-sdk/engine/cmd"
"git.apinb.com/bsm-sdk/engine/configure"
2024-02-28 12:30:42 +08:00
"git.apinb.com/bsm-sdk/engine/encipher"
2024-02-11 01:31:01 +08:00
"git.apinb.com/bsm-sdk/engine/env"
"git.apinb.com/bsm-sdk/engine/print"
"git.apinb.com/bsm-sdk/engine/vars"
"github.com/zeromicro/go-zero/core/prometheus"
"github.com/zeromicro/go-zero/core/trace"
)
func Register(srvKey string, cfg any) {
vars.ServiceKey = srvKey
// get os env.
env.NewEnv()
// open side cmd.
cmd.NewCmd()
2024-02-28 12:30:42 +08:00
encipher.New()
2024-02-13 22:41:20 +08:00
print.Info("[Blocks Service] %s Starting...", vars.ServiceKey)
2024-02-11 01:31:01 +08:00
// set config args.
args := map[string]string{
"ServiceKey": srvKey,
"Workspace": env.MeshEnv.Workspace,
"RuntimeMode": env.MeshEnv.RuntimeMode,
}
// get config file.
cf := fmt.Sprintf("%s_%s.yaml", srvKey, env.MeshEnv.RuntimeMode)
cf = filepath.Join(env.MeshEnv.Prefix, "etc", cf)
configure.LoadYamlFile(cf, args, cfg)
return
}
func Start(addr string) {
print.Info("[Blocks Service] %s Workspace: %s", vars.ServiceKey, env.MeshEnv.Workspace)
print.Info("[Blocks Service] %s Listen Addr: %s", vars.ServiceKey, addr)
print.Info("[Blocks Service] %s Runtime Mode: %s", vars.ServiceKey, env.MeshEnv.RuntimeMode)
}
func Done(p *prometheus.Config, t *trace.Config) {
if p != nil && p.Host != "" {
print.Info("[Blocks Service] %s Prometheus Addr: http://%s:%d%s", vars.ServiceKey, p.Host, p.Port, p.Path)
}
if t != nil && t.Endpoint != "" {
print.Info("[Blocks Service] %s Telemetry Endpoint: %s", vars.ServiceKey, t.Endpoint)
}
print.Info("[Blocks Service] %s Service Build: Version %s, Go Version %s By %s", vars.ServiceKey, vars.VERSION, vars.GO_VERSION, vars.BUILD_TIME)
print.Success("[Blocks Service] %s Service Grpc Register & Runing Success . ", vars.ServiceKey)
}