Compare commits

...

2 Commits

Author SHA1 Message Date
e184fff689 add conf.PrintInfo 2025-03-27 03:08:59 +08:00
33d1b2e0ee add SetOptions 2025-03-27 02:52:01 +08:00
2 changed files with 21 additions and 0 deletions

View File

@@ -12,6 +12,7 @@ import (
"git.apinb.com/bsm-sdk/core/env"
"git.apinb.com/bsm-sdk/core/print"
"git.apinb.com/bsm-sdk/core/utils"
"git.apinb.com/bsm-sdk/core/vars"
yaml "gopkg.in/yaml.v3"
)
@@ -56,6 +57,12 @@ func NotNil(values ...string) {
}
}
func PrintInfo(port int) {
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 {
if port <= 0 || port >= 65535 {
r := rand.New(rand.NewPCG(1000, uint64(time.Now().UnixNano())))

View File

@@ -8,6 +8,20 @@ import (
"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.
func NewPostgreSql(dsn string, options *types.SqlOptions) (*gorm.DB, error) {
var err error