Compare commits

...

5 Commits

Author SHA1 Message Date
yanweidong fe3e02370c fix,upd module 2024-12-03 18:53:11 +08:00
yanweidong 3dfadd7a30 dev 2024-12-02 11:41:17 +08:00
yanweidong 175848c47e dev 2024-12-02 11:28:37 +08:00
yanweidong 839d85d493 add err code 2024-10-15 12:53:06 +08:00
yanweidong 3b5719bc91 更新 types/etcd.go 2024-10-03 20:52:35 +08:00
8 changed files with 49 additions and 12 deletions

30
database/sql/ext.go Normal file
View File

@ -0,0 +1,30 @@
package sql
import "strings"
// key,value To like sql
func Like(key, val string) string {
if val == "" {
return ""
}
key = strings.TrimSpace(key)
val = strings.TrimSpace(val)
return key + " LIKE '%" + val + "%'"
}
// map strings to like sqls
func Likes(in map[string]string) string {
var ar []string
for key, val := range in {
sql := Like(key, val)
if sql != "" {
ar = append(ar, sql)
}
}
if len(ar) == 0 {
return ""
}
return strings.Join(ar, " AND ")
}

View File

@ -24,14 +24,14 @@ func NewPostgreSql(dsn string, options *types.SqlOptions) (*gorm.DB, error) {
}
//控制台和文件同时输出日志
var newLogger = setLogger(vars.ServiceKey, options.LogStdout)
//var newLogger = setLogger(vars.ServiceKey, options.LogStdout)
gormDb, err := gorm.Open(postgres.New(postgres.Config{
DSN: dsn,
// PreferSimpleProtocol: true, disables implicit prepared statement usage
}), &gorm.Config{
Logger: newLogger,
//Logger:newLogger,
DisableForeignKeyConstraintWhenMigrating: true,
NamingStrategy: schema.NamingStrategy{
SingularTable: true, // 使用单数表名,启用该选项,此时,`User` 的表名应该是 `t_user`

2
env/env.go vendored
View File

@ -14,7 +14,7 @@ var MeshEnv *types.MeshEnv = nil
func NewEnv() *types.MeshEnv {
if MeshEnv == nil {
MeshEnv = &types.MeshEnv{
Workspace: GetEnvDefault("BlocksMesh_Workspace", "bsm"),
Workspace: GetEnvDefault("BlocksMesh_Workspace", "def"),
JwtSecretKey: GetEnvDefault("BlocksMesh_JwtSecretKey", "Cblocksmesh2022C"),
RuntimeMode: strings.ToLower(GetEnvDefault("BlocksMesh_RuntimeMode", "dev")),
}

View File

@ -14,4 +14,5 @@ var (
ErrAuthClient = Errorf(209, "Auth Token Client Not Passed")
ErrJsonDecode = Errorf(210, "Auth JSON Decode Error")
ErrJsonEncode = Errorf(211, "Auth JSON Encode Error")
ErrAccountNotFound = Errorf(202, "Account Not Found")
)

2
go.mod
View File

@ -1,3 +1,3 @@
module git.apinb.com/bsm-sdk/engine
go 1.23
go 1.23.3

View File

@ -34,7 +34,7 @@ func Register(srvKey string, cfg any) {
// get config file.
cf := fmt.Sprintf("%s_%s.yaml", srvKey, env.MeshEnv.RuntimeMode)
cf = filepath.Join(env.MeshEnv.Prefix, "etc", cf)
print.Info("[Blocks Service] %s Config File: %s", vars.ServiceKey, cf)
configure.LoadYamlFile(cf, args, cfg)
return

View File

@ -18,10 +18,16 @@ type (
Debug bool
}
// standard ID,Identity definition.
Std_IDIdentity struct {
ID uint `gorm:"primarykey;" json:"id"`
Identity string `gorm:"column:identity;type:varchar(36);uniqueIndex;" json:"identity"` // 唯一标识24位NanoID,36位为ULID
}
// standard ID,Created,Updated,Deleted definition.
Std_IICUDS struct {
ID uint `gorm:"primarykey;" json:"id"`
Identity string `gorm:"column:identity;type:varchar(36);uniqueIndex;" json:"identity"` // 唯一标识24位NanoID,36位为UUID
Identity string `gorm:"column:identity;type:varchar(36);uniqueIndex;" json:"identity"` // 唯一标识24位NanoID,36位为ULID
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index;" json:"deleted_at"`
@ -45,7 +51,7 @@ type (
// standard PassportID,PassportIdentity definition.
Std_Passport struct {
PassportID uint `gorm:"column:passport_id;Index;" json:"passport_id"`
PassportIdentity string `gorm:"column:passport_identity;type:varchar(36);Index;" json:"passport_identity"` // 用户唯一标识24位NanoID,36位为UUID
PassportIdentity string `gorm:"column:passport_identity;type:varchar(36);Index;" json:"passport_identity"` // 用户唯一标识24位NanoID,36位为ULID
}
// standard ID definition.
@ -55,7 +61,7 @@ type (
// standard Identity definition.
Std_Identity struct {
Identity string `gorm:"column:identity;type:varchar(36);uniqueIndex;" json:"identity"` // 唯一标识24位NanoID,36位为UUID
Identity string `gorm:"column:identity;type:varchar(36);uniqueIndex;" json:"identity"` // 唯一标识24位NanoID,36位为ULID
}
// standard Status definition.

View File

@ -2,11 +2,11 @@ package types
type Etcd struct {
Endpoints []string `json:"Endpoints"`
Tls EtcdTls `json:"Tls"`
Tls EtcdTls `json:"Tls,optional"`
}
type EtcdTls struct {
Ca string `json:"Ca"`
Cert string `json:"Cert"`
CertKey string `json:"CertKey" `
Ca string `json:"Ca,optional"`
Cert string `json:"Cert,optional"`
CertKey string `json:"CertKey,optional" `
}