```
refactor(print): 将 print 包重命名为 printer 并更新所有引用 将项目中的 print 包统一重命名为 printer,以避免与标准库或第三方库产生命名冲突。同时, 更新了所有相关模块对该包的引用,确保功能一致性和代码可维护性。 涉及文件包括: - conf/new.go - infra/service.go - service/register.go - service/service.go - with/databases.go - with/etcd.go - with/memory.go - with/redis.go 此外,删除了以下已废弃或未使用的代码文件: - cmd/cmd.go - data/map_float.go - data/map_string.go - oplog/new.go - oplog/types.go - print/print.go - utils/ext.go ```
This commit is contained in:
36
service/cmd.go
Normal file
36
service/cmd.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
)
|
||||
|
||||
func NewCmd() {
|
||||
if len(os.Args) > 1 {
|
||||
parseArgs(os.Args[1])
|
||||
}
|
||||
}
|
||||
|
||||
func parseArgs(cmd string) {
|
||||
cmd = strings.ToLower(cmd)
|
||||
switch cmd {
|
||||
case "-v", "--v", "-version", "--version":
|
||||
versionCmd()
|
||||
case "--json":
|
||||
versionCmdJson()
|
||||
}
|
||||
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
func versionCmd() {
|
||||
fmt.Printf("[Blocks Service: %s] Version: %s \n", vars.ServiceKey, vars.VERSION)
|
||||
fmt.Printf("[Blocks Service: %s] Compile: %s by %s build.\n", vars.ServiceKey, vars.GO_VERSION, vars.BUILD_TIME)
|
||||
}
|
||||
|
||||
func versionCmdJson() {
|
||||
fmt.Printf("{\"version\":\"%s\",\"build_time\":\"%s\"}\n", vars.VERSION, vars.BUILD_TIME)
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/print"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
clientv3 "go.etcd.io/etcd/client/v3"
|
||||
)
|
||||
@@ -96,7 +96,7 @@ func (s *ServiceRegister) SetAnonymous(key string, urls []string) {
|
||||
// remove reppeat, clear service all anonymous uri.
|
||||
anonymous, err := s.cli.Get(context.Background(), key)
|
||||
if err != nil {
|
||||
print.Error("[BSM Register] Get Anonymous Fail: %v", err)
|
||||
printer.Error("[BSM Register] Get Anonymous Fail: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -113,9 +113,9 @@ func (s *ServiceRegister) SetAnonymous(key string, urls []string) {
|
||||
_, err = s.cli.Put(context.Background(), key, newAnonymous)
|
||||
|
||||
if err != nil {
|
||||
print.Error("[BSM Register] Anonymous Fail.")
|
||||
printer.Error("[BSM Register] Anonymous Fail.")
|
||||
} else {
|
||||
print.Info("[BSM Register] Anonymous: %s", newAnonymous)
|
||||
printer.Info("[BSM Register] Anonymous: %s", newAnonymous)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/conf"
|
||||
"git.apinb.com/bsm-sdk/core/env"
|
||||
"git.apinb.com/bsm-sdk/core/print"
|
||||
"git.apinb.com/bsm-sdk/core/printer"
|
||||
"git.apinb.com/bsm-sdk/core/vars"
|
||||
clientv3 "go.etcd.io/etcd/client/v3"
|
||||
"google.golang.org/grpc"
|
||||
@@ -48,15 +48,15 @@ func Addr(ip string, port int) string {
|
||||
}
|
||||
|
||||
func (s *Service) Start() {
|
||||
print.Info("[BSM - %s] Service Starting ...", vars.ServiceKey)
|
||||
printer.Info("[BSM - %s] Service Starting ...", vars.ServiceKey)
|
||||
|
||||
// register to etcd.
|
||||
if s.Opts.MsConf != nil && s.Opts.MsConf.Enable {
|
||||
if s.Opts.EtcdClient == nil {
|
||||
print.Error("[BSM Register] Etcd Client is nil.")
|
||||
printer.Error("[BSM Register] Etcd Client is nil.")
|
||||
os.Exit(1)
|
||||
}
|
||||
print.Info("[BSM - %s] Registering Service to Etcd ...", vars.ServiceKey)
|
||||
printer.Info("[BSM - %s] Registering Service to Etcd ...", vars.ServiceKey)
|
||||
// get methods
|
||||
methods := FoundGrpcMethods(s.GrpcSrv)
|
||||
|
||||
@@ -88,13 +88,13 @@ func (s *Service) Start() {
|
||||
panic(err)
|
||||
}
|
||||
}()
|
||||
print.Success("[BSM - %s] Grpc %s Runing Success !", vars.ServiceKey, s.Opts.Addr)
|
||||
printer.Success("[BSM - %s] Grpc %s Runing Success !", vars.ServiceKey, s.Opts.Addr)
|
||||
|
||||
if s.Opts.GatewayConf != nil && s.Opts.GatewayConf.Enable {
|
||||
addr := Addr("0.0.0.0", s.Opts.GatewayConf.Port)
|
||||
go s.Gateway(s.Opts.Addr, addr)
|
||||
|
||||
print.Success("[BSM - %s] Http %s Runing Success!", vars.ServiceKey, addr)
|
||||
printer.Success("[BSM - %s] Http %s Runing Success!", vars.ServiceKey, addr)
|
||||
}
|
||||
|
||||
select {}
|
||||
@@ -111,7 +111,7 @@ func (s *Service) Gateway(grpcAddr string, httpAddr string) {
|
||||
func (s *Service) Use(initFunc func() error) {
|
||||
err := (initFunc)()
|
||||
if err != nil {
|
||||
print.Error(err.Error())
|
||||
printer.Error(err.Error())
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user