```
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:
parent
21716c4340
commit
25386cf0e1
|
@ -1,34 +1,32 @@
|
||||||
package data
|
package mapsync
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// Cache
|
// sync map
|
||||||
CacheMapFloat *MapFloat
|
MapFloat *mapFloat
|
||||||
)
|
)
|
||||||
|
|
||||||
// lock
|
// lock
|
||||||
type MapFloat struct {
|
type mapFloat struct {
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
Data map[string]float64
|
Data map[string]float64
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMapFloat() *MapFloat {
|
func NewMapFloat() *mapFloat {
|
||||||
return &MapFloat{
|
return &mapFloat{
|
||||||
Data: make(map[string]float64),
|
Data: make(map[string]float64),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
func (c *mapFloat) Set(key string, val float64) {
|
||||||
func (c *MapFloat) All() map[string]float64 {
|
c.Lock()
|
||||||
c.RLock()
|
defer c.Unlock()
|
||||||
defer c.RUnlock()
|
c.Data[key] = val
|
||||||
|
|
||||||
return c.Data
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *MapFloat) Get(key string) float64 {
|
func (c *mapFloat) Get(key string) float64 {
|
||||||
c.RLock()
|
c.RLock()
|
||||||
defer c.RUnlock()
|
defer c.RUnlock()
|
||||||
|
|
||||||
|
@ -40,13 +38,14 @@ func (c *MapFloat) Get(key string) float64 {
|
||||||
return vals
|
return vals
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *MapFloat) Set(key string, val float64) {
|
func (c *mapFloat) Del(key string) {
|
||||||
c.Lock()
|
c.Lock()
|
||||||
defer c.Unlock()
|
defer c.Unlock()
|
||||||
c.Data[key] = val
|
|
||||||
|
delete(c.Data, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *MapFloat) Keys() (keys []string) {
|
func (c *mapFloat) Keys() (keys []string) {
|
||||||
c.RLock()
|
c.RLock()
|
||||||
defer c.RUnlock()
|
defer c.RUnlock()
|
||||||
|
|
||||||
|
@ -56,3 +55,10 @@ func (c *MapFloat) Keys() (keys []string) {
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *mapFloat) All() map[string]float64 {
|
||||||
|
c.RLock()
|
||||||
|
defer c.RUnlock()
|
||||||
|
|
||||||
|
return c.Data
|
||||||
|
}
|
|
@ -0,0 +1,64 @@
|
||||||
|
package mapsync
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// sync map
|
||||||
|
MapInt *mapInt
|
||||||
|
)
|
||||||
|
|
||||||
|
// lock
|
||||||
|
type mapInt struct {
|
||||||
|
sync.RWMutex
|
||||||
|
Data map[string]int
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewMapInt() *mapInt {
|
||||||
|
return &mapInt{
|
||||||
|
Data: make(map[string]int),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *mapInt) Set(key string, val int) {
|
||||||
|
c.Lock()
|
||||||
|
defer c.Unlock()
|
||||||
|
c.Data[key] = val
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *mapInt) Get(key string) int {
|
||||||
|
c.RLock()
|
||||||
|
defer c.RUnlock()
|
||||||
|
|
||||||
|
vals, ok := c.Data[key]
|
||||||
|
if !ok {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return vals
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *mapInt) Del(key string) {
|
||||||
|
c.Lock()
|
||||||
|
defer c.Unlock()
|
||||||
|
|
||||||
|
delete(c.Data, key)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *mapInt) All() map[string]int {
|
||||||
|
c.RLock()
|
||||||
|
defer c.RUnlock()
|
||||||
|
|
||||||
|
return c.Data
|
||||||
|
}
|
||||||
|
func (c *mapInt) Keys() (keys []string) {
|
||||||
|
c.RLock()
|
||||||
|
defer c.RUnlock()
|
||||||
|
|
||||||
|
for k, _ := range c.Data {
|
||||||
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
|
@ -0,0 +1,64 @@
|
||||||
|
package mapsync
|
||||||
|
|
||||||
|
import (
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// sync map
|
||||||
|
MapString *mapString
|
||||||
|
)
|
||||||
|
|
||||||
|
// lock
|
||||||
|
type mapString struct {
|
||||||
|
sync.RWMutex
|
||||||
|
Data map[string]string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewMapString() *mapString {
|
||||||
|
return &mapString{
|
||||||
|
Data: make(map[string]string),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *mapString) Set(key, val string) {
|
||||||
|
c.Lock()
|
||||||
|
defer c.Unlock()
|
||||||
|
c.Data[key] = val
|
||||||
|
}
|
||||||
|
func (c *mapString) Get(key string) string {
|
||||||
|
c.RLock()
|
||||||
|
defer c.RUnlock()
|
||||||
|
|
||||||
|
vals, ok := c.Data[key]
|
||||||
|
if !ok {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return vals
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *mapString) Del(key string) {
|
||||||
|
c.Lock()
|
||||||
|
defer c.Unlock()
|
||||||
|
|
||||||
|
delete(c.Data, key)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *mapString) Keys() (keys []string) {
|
||||||
|
c.RLock()
|
||||||
|
defer c.RUnlock()
|
||||||
|
|
||||||
|
for k, _ := range c.Data {
|
||||||
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *mapString) All() map[string]string {
|
||||||
|
c.RLock()
|
||||||
|
defer c.RUnlock()
|
||||||
|
|
||||||
|
return c.Data
|
||||||
|
}
|
12
conf/new.go
12
conf/new.go
|
@ -11,7 +11,7 @@ import (
|
||||||
"math/rand/v2"
|
"math/rand/v2"
|
||||||
|
|
||||||
"git.apinb.com/bsm-sdk/core/env"
|
"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/utils"
|
"git.apinb.com/bsm-sdk/core/utils"
|
||||||
"git.apinb.com/bsm-sdk/core/vars"
|
"git.apinb.com/bsm-sdk/core/vars"
|
||||||
yaml "gopkg.in/yaml.v3"
|
yaml "gopkg.in/yaml.v3"
|
||||||
|
@ -36,8 +36,8 @@ func New(srvKey string, cfg any) {
|
||||||
cfp = filepath.Join(env.Runtime.Prefix, "etc", cfp)
|
cfp = filepath.Join(env.Runtime.Prefix, "etc", cfp)
|
||||||
}
|
}
|
||||||
|
|
||||||
print.Info("[BSM - %s] Config File: %s", srvKey, cfp)
|
printer.Info("[BSM - %s] Config File: %s", srvKey, cfp)
|
||||||
print.Info("[BSM - %s] Check Configure ...", vars.ServiceKey)
|
printer.Info("[BSM - %s] Check Configure ...", vars.ServiceKey)
|
||||||
|
|
||||||
// 读取配置文件内容
|
// 读取配置文件内容
|
||||||
yamlFile, err := os.ReadFile(cfp)
|
yamlFile, err := os.ReadFile(cfp)
|
||||||
|
@ -69,9 +69,9 @@ func NotNil(values ...string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func PrintInfo(addr string) {
|
func PrintInfo(addr string) {
|
||||||
print.Success("[BSM - %s] Config Check Success.", vars.ServiceKey)
|
printer.Success("[BSM - %s] Config Check Success.", vars.ServiceKey)
|
||||||
print.Info("[BSM - %s] Service Name: %s", vars.ServiceKey, vars.ServiceKey)
|
printer.Info("[BSM - %s] Service Name: %s", vars.ServiceKey, vars.ServiceKey)
|
||||||
print.Info("[BSM - %s] Runtime Mode: %s", vars.ServiceKey, env.Runtime.Mode)
|
printer.Info("[BSM - %s] Runtime Mode: %s", vars.ServiceKey, env.Runtime.Mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckPort(port string) string {
|
func CheckPort(port string) string {
|
||||||
|
|
|
@ -1,51 +0,0 @@
|
||||||
package data
|
|
||||||
|
|
||||||
import (
|
|
||||||
"sync"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
// Cache
|
|
||||||
CacheMapString *MapString
|
|
||||||
)
|
|
||||||
|
|
||||||
// lock
|
|
||||||
type MapString struct {
|
|
||||||
sync.RWMutex
|
|
||||||
Data map[string]string
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewMapString() *MapString {
|
|
||||||
return &MapString{
|
|
||||||
Data: make(map[string]string),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *MapString) Get(key string) string {
|
|
||||||
c.RLock()
|
|
||||||
defer c.RUnlock()
|
|
||||||
|
|
||||||
vals, ok := c.Data[key]
|
|
||||||
if !ok {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
return vals
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *MapString) Set(key, val string) {
|
|
||||||
c.Lock()
|
|
||||||
defer c.Unlock()
|
|
||||||
c.Data[key] = val
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *MapString) Keys() (keys []string) {
|
|
||||||
c.RLock()
|
|
||||||
defer c.RUnlock()
|
|
||||||
|
|
||||||
for k, _ := range c.Data {
|
|
||||||
keys = append(keys, k)
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
|
@ -1,4 +1,10 @@
|
||||||
package oplog
|
package infra
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
|
||||||
|
"git.apinb.com/bsm-sdk/core/utils"
|
||||||
|
)
|
||||||
|
|
||||||
type LogItem struct {
|
type LogItem struct {
|
||||||
OpID uint `json:"op_id"`
|
OpID uint `json:"op_id"`
|
||||||
|
@ -22,3 +28,10 @@ var (
|
||||||
Type_Other string = "other"
|
Type_Other string = "other"
|
||||||
Type_Create string = "create"
|
Type_Create string = "create"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func NewLogs(endpoint string, data []*LogItem) {
|
||||||
|
jsonBytes, _ := json.Marshal(data)
|
||||||
|
|
||||||
|
go utils.HttpPost(endpoint, nil, jsonBytes)
|
||||||
|
|
||||||
|
}
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.apinb.com/bsm-sdk/core/print"
|
"git.apinb.com/bsm-sdk/core/printer"
|
||||||
"git.apinb.com/bsm-sdk/core/utils"
|
"git.apinb.com/bsm-sdk/core/utils"
|
||||||
clientv3 "go.etcd.io/etcd/client/v3"
|
clientv3 "go.etcd.io/etcd/client/v3"
|
||||||
)
|
)
|
||||||
|
@ -37,10 +37,10 @@ func (s *service) Register(cli *clientv3.Client, serviceName string, port string
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
print.Info("[BSM Register] Service Key: %s", key)
|
printer.Info("[BSM Register] Service Key: %s", key)
|
||||||
print.Info("[BSM Register] Service Val: %s", serviceAddr)
|
printer.Info("[BSM Register] Service Val: %s", serviceAddr)
|
||||||
|
|
||||||
print.Success("[BSM Register] Service Register Complete.")
|
printer.Success("[BSM Register] Service Register Complete.")
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for keepAliveResp := range keepAliveChan {
|
for keepAliveResp := range keepAliveChan {
|
||||||
|
|
14
oplog/new.go
14
oplog/new.go
|
@ -1,14 +0,0 @@
|
||||||
package oplog
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"git.apinb.com/bsm-sdk/core/utils"
|
|
||||||
)
|
|
||||||
|
|
||||||
func New(endpoint string, data []*LogItem) {
|
|
||||||
jsonBytes, _ := json.Marshal(data)
|
|
||||||
|
|
||||||
go utils.HttpPost(endpoint, nil, jsonBytes)
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,6 +1,8 @@
|
||||||
package print
|
package printer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
@ -36,3 +38,11 @@ func Error(format string, a ...interface{}) {
|
||||||
message := fmt.Sprintf("\033[31m[Error] "+format+"\033[0m\n", a...)
|
message := fmt.Sprintf("\033[31m[Error] "+format+"\033[0m\n", a...)
|
||||||
logger.Print(message)
|
logger.Print(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Json(v any) {
|
||||||
|
jsonBy, _ := json.Marshal(v)
|
||||||
|
var out bytes.Buffer
|
||||||
|
json.Indent(&out, jsonBy, "", "\t")
|
||||||
|
out.WriteTo(os.Stdout)
|
||||||
|
fmt.Printf("\n")
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package cmd
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.apinb.com/bsm-sdk/core/print"
|
"git.apinb.com/bsm-sdk/core/printer"
|
||||||
"git.apinb.com/bsm-sdk/core/vars"
|
"git.apinb.com/bsm-sdk/core/vars"
|
||||||
clientv3 "go.etcd.io/etcd/client/v3"
|
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.
|
// remove reppeat, clear service all anonymous uri.
|
||||||
anonymous, err := s.cli.Get(context.Background(), key)
|
anonymous, err := s.cli.Get(context.Background(), key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
print.Error("[BSM Register] Get Anonymous Fail: %v", err)
|
printer.Error("[BSM Register] Get Anonymous Fail: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,9 +113,9 @@ func (s *ServiceRegister) SetAnonymous(key string, urls []string) {
|
||||||
_, err = s.cli.Put(context.Background(), key, newAnonymous)
|
_, err = s.cli.Put(context.Background(), key, newAnonymous)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
print.Error("[BSM Register] Anonymous Fail.")
|
printer.Error("[BSM Register] Anonymous Fail.")
|
||||||
} else {
|
} 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/conf"
|
||||||
"git.apinb.com/bsm-sdk/core/env"
|
"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"
|
"git.apinb.com/bsm-sdk/core/vars"
|
||||||
clientv3 "go.etcd.io/etcd/client/v3"
|
clientv3 "go.etcd.io/etcd/client/v3"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
|
@ -48,15 +48,15 @@ func Addr(ip string, port int) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) Start() {
|
func (s *Service) Start() {
|
||||||
print.Info("[BSM - %s] Service Starting ...", vars.ServiceKey)
|
printer.Info("[BSM - %s] Service Starting ...", vars.ServiceKey)
|
||||||
|
|
||||||
// register to etcd.
|
// register to etcd.
|
||||||
if s.Opts.MsConf != nil && s.Opts.MsConf.Enable {
|
if s.Opts.MsConf != nil && s.Opts.MsConf.Enable {
|
||||||
if s.Opts.EtcdClient == nil {
|
if s.Opts.EtcdClient == nil {
|
||||||
print.Error("[BSM Register] Etcd Client is nil.")
|
printer.Error("[BSM Register] Etcd Client is nil.")
|
||||||
os.Exit(1)
|
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
|
// get methods
|
||||||
methods := FoundGrpcMethods(s.GrpcSrv)
|
methods := FoundGrpcMethods(s.GrpcSrv)
|
||||||
|
|
||||||
|
@ -88,13 +88,13 @@ func (s *Service) Start() {
|
||||||
panic(err)
|
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 {
|
if s.Opts.GatewayConf != nil && s.Opts.GatewayConf.Enable {
|
||||||
addr := Addr("0.0.0.0", s.Opts.GatewayConf.Port)
|
addr := Addr("0.0.0.0", s.Opts.GatewayConf.Port)
|
||||||
go s.Gateway(s.Opts.Addr, addr)
|
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 {}
|
select {}
|
||||||
|
@ -111,7 +111,7 @@ func (s *Service) Gateway(grpcAddr string, httpAddr string) {
|
||||||
func (s *Service) Use(initFunc func() error) {
|
func (s *Service) Use(initFunc func() error) {
|
||||||
err := (initFunc)()
|
err := (initFunc)()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
print.Error(err.Error())
|
printer.Error(err.Error())
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
12
utils/ext.go
12
utils/ext.go
|
@ -1,10 +1,6 @@
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
@ -37,11 +33,3 @@ func ParseParams(in map[string]string) map[string]interface{} {
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
func PrintJson(v any) {
|
|
||||||
jsonBy, _ := json.Marshal(v)
|
|
||||||
var out bytes.Buffer
|
|
||||||
json.Indent(&out, jsonBy, "", "\t")
|
|
||||||
out.WriteTo(os.Stdout)
|
|
||||||
fmt.Printf("\n")
|
|
||||||
}
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ package with
|
||||||
import (
|
import (
|
||||||
"git.apinb.com/bsm-sdk/core/conf"
|
"git.apinb.com/bsm-sdk/core/conf"
|
||||||
"git.apinb.com/bsm-sdk/core/database"
|
"git.apinb.com/bsm-sdk/core/database"
|
||||||
"git.apinb.com/bsm-sdk/core/print"
|
"git.apinb.com/bsm-sdk/core/printer"
|
||||||
"git.apinb.com/bsm-sdk/core/types"
|
"git.apinb.com/bsm-sdk/core/types"
|
||||||
"git.apinb.com/bsm-sdk/core/vars"
|
"git.apinb.com/bsm-sdk/core/vars"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
@ -15,12 +15,12 @@ func Databases(cfg *conf.DBConf, opts *types.SqlOptions) *gorm.DB {
|
||||||
}
|
}
|
||||||
|
|
||||||
// print inform.
|
// print inform.
|
||||||
print.Info("[BSM - %s] Databases: %v", vars.ServiceKey, cfg)
|
printer.Info("[BSM - %s] Databases: %v", vars.ServiceKey, cfg)
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
db, err := database.NewDatabase(cfg.Driver, cfg.Source, opts)
|
db, err := database.NewDatabase(cfg.Driver, cfg.Source, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
print.Error("Database Init Failed !")
|
printer.Error("Database Init Failed !")
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
return db
|
return db
|
||||||
|
|
10
with/etcd.go
10
with/etcd.go
|
@ -5,13 +5,13 @@ import (
|
||||||
|
|
||||||
"git.apinb.com/bsm-sdk/core/conf"
|
"git.apinb.com/bsm-sdk/core/conf"
|
||||||
"git.apinb.com/bsm-sdk/core/errcode"
|
"git.apinb.com/bsm-sdk/core/errcode"
|
||||||
"git.apinb.com/bsm-sdk/core/print"
|
"git.apinb.com/bsm-sdk/core/printer"
|
||||||
"git.apinb.com/bsm-sdk/core/vars"
|
"git.apinb.com/bsm-sdk/core/vars"
|
||||||
"go.etcd.io/etcd/client/pkg/v3/transport"
|
"go.etcd.io/etcd/client/pkg/v3/transport"
|
||||||
clientv3 "go.etcd.io/etcd/client/v3"
|
clientv3 "go.etcd.io/etcd/client/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Etcd(cfg *conf.EtcdConf) (cli *clientv3.Client){
|
func Etcd(cfg *conf.EtcdConf) (cli *clientv3.Client) {
|
||||||
if cfg == nil || len(cfg.Endpoints) == 0 {
|
if cfg == nil || len(cfg.Endpoints) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ func Etcd(cfg *conf.EtcdConf) (cli *clientv3.Client){
|
||||||
}
|
}
|
||||||
tlsConfig, err := tlsInfo.ClientConfig()
|
tlsConfig, err := tlsInfo.ClientConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
print.Error(errcode.ErrEtcd.Error())
|
printer.Error(errcode.ErrEtcd.Error())
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
etcdCfg.TLS = tlsConfig
|
etcdCfg.TLS = tlsConfig
|
||||||
|
@ -44,11 +44,11 @@ func Etcd(cfg *conf.EtcdConf) (cli *clientv3.Client){
|
||||||
var err error
|
var err error
|
||||||
cli, err = clientv3.New(etcdCfg)
|
cli, err = clientv3.New(etcdCfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
print.Error(errcode.ErrEtcd.Error())
|
printer.Error(errcode.ErrEtcd.Error())
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// print inform.
|
// print inform.
|
||||||
print.Info("[BSM - %s] Service Center: %v", vars.ServiceKey, cfg.Endpoints)
|
printer.Info("[BSM - %s] Service Center: %v", vars.ServiceKey, cfg.Endpoints)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.apinb.com/bsm-sdk/core/print"
|
"git.apinb.com/bsm-sdk/core/printer"
|
||||||
"git.apinb.com/bsm-sdk/core/vars"
|
"git.apinb.com/bsm-sdk/core/vars"
|
||||||
"github.com/allegro/bigcache/v3"
|
"github.com/allegro/bigcache/v3"
|
||||||
)
|
)
|
||||||
|
@ -27,10 +27,10 @@ func Memory(opts *bigcache.Config) (cli *bigcache.BigCache) {
|
||||||
var err error
|
var err error
|
||||||
cli, err = bigcache.New(context.Background(), *opts)
|
cli, err = bigcache.New(context.Background(), *opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
print.Error("Memory Cache Fatal Error")
|
printer.Error("Memory Cache Fatal Error")
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
print.Success("[BSM - %s] Memory Cache: Shards=%d, MaxEntrySize=%d", vars.ServiceKey, opts.Shards, opts.MaxEntrySize)
|
printer.Success("[BSM - %s] Memory Cache: Shards=%d, MaxEntrySize=%d", vars.ServiceKey, opts.Shards, opts.MaxEntrySize)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package with
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.apinb.com/bsm-sdk/core/cache/redis"
|
"git.apinb.com/bsm-sdk/core/cache/redis"
|
||||||
"git.apinb.com/bsm-sdk/core/print"
|
"git.apinb.com/bsm-sdk/core/printer"
|
||||||
"git.apinb.com/bsm-sdk/core/vars"
|
"git.apinb.com/bsm-sdk/core/vars"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ func RedisCache(cfg string) (cli *redis.RedisClient) {
|
||||||
cli = redis.New(cfg, vars.ServiceKey)
|
cli = redis.New(cfg, vars.ServiceKey)
|
||||||
|
|
||||||
// print inform.
|
// print inform.
|
||||||
print.Info("[BSM - %s] Cache: %s, DBIndex: %d", vars.ServiceKey, cfg, cli.DB)
|
printer.Info("[BSM - %s] Cache: %s, DBIndex: %d", vars.ServiceKey, cfg, cli.DB)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue