Compare commits

..

4 Commits

Author SHA1 Message Date
04451d4b2f add conf.PrintInfo 2025-03-27 03:10:56 +08:00
e184fff689 add conf.PrintInfo 2025-03-27 03:08:59 +08:00
33d1b2e0ee add SetOptions 2025-03-27 02:52:01 +08:00
433cd1f8bc fix hash key 2025-03-27 02:49:44 +08:00
3 changed files with 25 additions and 1 deletions

View File

@@ -59,6 +59,6 @@ func New(dsn string, hashRadix string) *RedisClient {
func Hash(s string) int { func Hash(s string) int {
h := fnv.New32a() h := fnv.New32a()
h.Write([]byte(s)) h.Write([]byte(strings.ToLower(s)))
return int(h.Sum32()) % vars.RedisShardings return int(h.Sum32()) % vars.RedisShardings
} }

View File

@@ -12,6 +12,7 @@ import (
"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/print"
"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"
) )
@@ -28,7 +29,9 @@ func New(srvKey string, cfg any) {
// 构造配置文件路径,输出配置文件信息 // 构造配置文件路径,输出配置文件信息
cfp := fmt.Sprintf("%s_%s.yaml", strings.ToLower(srvKey), env.Runtime.Mode) cfp := fmt.Sprintf("%s_%s.yaml", strings.ToLower(srvKey), env.Runtime.Mode)
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) print.Info("[BSM - %s] Config File: %s", srvKey, cfp)
print.Info("[BSM - %s] Check Configure ...", vars.ServiceKey)
// 读取配置文件内容 // 读取配置文件内容
yamlFile, err := os.ReadFile(cfp) yamlFile, err := os.ReadFile(cfp)
@@ -56,6 +59,13 @@ func NotNil(values ...string) {
} }
} }
func PrintInfo(port int) {
print.Success("[BSM - %s] Config Check Success.", vars.ServiceKey)
print.Info("[BSM - %s] Service Name: %s", vars.ServiceKey, vars.ServiceKey)
print.Info("[BSM - %s] Runtime Mode: %s", vars.ServiceKey, env.Runtime.Mode)
print.Info("[BSM - %s] Listen Addr: %s:%d", vars.ServiceKey, utils.GetLocationIP(), port)
}
func CheckPort(port int) int { func CheckPort(port int) int {
if port <= 0 || port >= 65535 { if port <= 0 || port >= 65535 {
r := rand.New(rand.NewPCG(1000, uint64(time.Now().UnixNano()))) r := rand.New(rand.NewPCG(1000, uint64(time.Now().UnixNano())))

View File

@@ -8,6 +8,20 @@ import (
"gorm.io/gorm/schema" "gorm.io/gorm/schema"
) )
func SetOptions(options *types.SqlOptions) *types.SqlOptions {
if options == nil {
options = &types.SqlOptions{
MaxIdleConns: vars.SqlOptionMaxIdleConns,
MaxOpenConns: vars.SqlOptionMaxIdleConns,
ConnMaxLifetime: vars.SqlOptionConnMaxLifetime,
LogStdout: false,
Debug: false,
}
}
return options
}
// new grom db. // new grom db.
func NewPostgreSql(dsn string, options *types.SqlOptions) (*gorm.DB, error) { func NewPostgreSql(dsn string, options *types.SqlOptions) (*gorm.DB, error) {
var err error var err error