Compare commits
12 Commits
Author | SHA1 | Date |
---|---|---|
yanweidong | fe3e02370c | |
yanweidong | 3dfadd7a30 | |
yanweidong | 175848c47e | |
yanweidong | 839d85d493 | |
yanweidong | 3b5719bc91 | |
yanweidong | ec2bf11981 | |
yanweidong | 9bb2a1d730 | |
yanweidong | d645a49c97 | |
yanweidong | a8efe29c7f | |
yanweidong | 3d609bfba8 | |
yanweidong | 8537320513 | |
david | 0be9490840 |
|
@ -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 ")
|
||||
}
|
|
@ -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`
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"git.apinb.com/bsm-sdk/engine/types"
|
||||
"git.apinb.com/bsm-sdk/engine/utils"
|
||||
)
|
||||
|
||||
var MeshEnv *types.MeshEnv = nil
|
||||
|
@ -13,11 +14,16 @@ var MeshEnv *types.MeshEnv = nil
|
|||
func NewEnv() *types.MeshEnv {
|
||||
if MeshEnv == nil {
|
||||
MeshEnv = &types.MeshEnv{
|
||||
Workspace: GetEnvDefault("BlocksMesh_Workspace", "bsm"),
|
||||
Prefix: GetEnvDefault("BlocksMesh_Prefix", "/usr/local/bsm"),
|
||||
Workspace: GetEnvDefault("BlocksMesh_Workspace", "def"),
|
||||
JwtSecretKey: GetEnvDefault("BlocksMesh_JwtSecretKey", "Cblocksmesh2022C"),
|
||||
RuntimeMode: strings.ToLower(GetEnvDefault("BlocksMesh_RuntimeMode", "dev")),
|
||||
}
|
||||
|
||||
if MeshEnv.RuntimeMode == "dev" {
|
||||
MeshEnv.Prefix = GetEnvDefault("BlocksMesh_Prefix", utils.GetCurrentPath())
|
||||
} else {
|
||||
MeshEnv.Prefix = GetEnvDefault("BlocksMesh_Prefix", "/usr/local/bsm")
|
||||
}
|
||||
}
|
||||
return MeshEnv
|
||||
}
|
||||
|
@ -26,9 +32,14 @@ func NewEnv() *types.MeshEnv {
|
|||
func NewBaseEnv() *types.MeshEnv {
|
||||
if MeshEnv == nil {
|
||||
MeshEnv = &types.MeshEnv{
|
||||
Prefix: GetEnvDefault("BlocksMesh_Prefix", "/usr/local/bsm"),
|
||||
RuntimeMode: strings.ToLower(GetEnvDefault("BlocksMesh_RuntimeMode", "dev")),
|
||||
}
|
||||
|
||||
if MeshEnv.RuntimeMode == "dev" {
|
||||
MeshEnv.Prefix = GetEnvDefault("BlocksMesh_Prefix", utils.GetCurrentPath())
|
||||
} else {
|
||||
MeshEnv.Prefix = GetEnvDefault("BlocksMesh_Prefix", "/usr/local/bsm")
|
||||
}
|
||||
}
|
||||
return MeshEnv
|
||||
}
|
||||
|
|
|
@ -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,9 +2,9 @@ package service
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"git.apinb.com/bsm-sdk/engine/encipher"
|
||||
"git.apinb.com/bsm-sdk/engine/exception"
|
||||
"git.apinb.com/bsm-sdk/engine/types"
|
||||
"google.golang.org/grpc/metadata"
|
||||
|
@ -23,14 +23,15 @@ func ParseMetaCtx(ctx context.Context, opts *ParseOptions) (*types.JwtClaims, er
|
|||
return nil, exception.ErrAuthNotFound
|
||||
}
|
||||
|
||||
var Authorizations []string = md.Get("authorization")
|
||||
var Authorizations []string = md.Get("authorization_claims")
|
||||
if len(Authorizations) == 0 || Authorizations[0] == "" {
|
||||
return nil, exception.ErrAuthNotFound
|
||||
}
|
||||
|
||||
claims, err := encipher.ParseTokenAes(Authorizations[0])
|
||||
var claims types.JwtClaims
|
||||
err := json.Unmarshal([]byte(Authorizations[0]), &claims)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, exception.ErrAuthParseFail
|
||||
}
|
||||
|
||||
if opts != nil {
|
||||
|
@ -39,6 +40,6 @@ func ParseMetaCtx(ctx context.Context, opts *ParseOptions) (*types.JwtClaims, er
|
|||
}
|
||||
}
|
||||
|
||||
return claims, nil
|
||||
return &claims, nil
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
12
types/db.go
12
types/db.go
|
@ -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.
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package types
|
||||
|
||||
type Etcd struct {
|
||||
Endpoints []string `json:"endpoints"`
|
||||
Tls EtcdTls `json:",optional"`
|
||||
Endpoints []string `json:"Endpoints"`
|
||||
Tls EtcdTls `json:"Tls,optional"`
|
||||
}
|
||||
|
||||
type EtcdTls struct {
|
||||
Ca string `json:"ca,optional"`
|
||||
Cert string `json:"cert,optional"`
|
||||
CertKey string `json:"cert_key,optional" `
|
||||
Ca string `json:"Ca,optional"`
|
||||
Cert string `json:"Cert,optional"`
|
||||
CertKey string `json:"CertKey,optional" `
|
||||
}
|
||||
|
|
|
@ -1,31 +1,10 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/jaevor/go-nanoid"
|
||||
ulid "github.com/oklog/ulid/v2"
|
||||
)
|
||||
|
||||
func NanoID() string {
|
||||
nanoid, _ := nanoid.CustomASCII("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 21)
|
||||
return nanoid()
|
||||
}
|
||||
|
||||
func NanoIDInt() (id int64, err error) {
|
||||
decenaryID, err := nanoid.CustomASCII("0123456789", 18)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
id, err = strconv.ParseInt(decenaryID(), 10, 64)
|
||||
return
|
||||
}
|
||||
|
||||
func UUID() string {
|
||||
return uuid.NewString()
|
||||
}
|
||||
|
||||
// remove nanoid,uuid,replace to ulid
|
||||
func ULID() string {
|
||||
return ulid.Make().String()
|
||||
}
|
||||
|
|
|
@ -99,7 +99,7 @@ func HttpPost(url string, header map[string]string, data []byte) ([]byte, error)
|
|||
}
|
||||
|
||||
request.Header.Set("Content-Type", "application/json;charset=UTF-8")
|
||||
request.Header.Set("Request-Id", NanoID())
|
||||
request.Header.Set("Request-Id", ULID())
|
||||
|
||||
for key, val := range header {
|
||||
request.Header.Set(key, val)
|
||||
|
|
Loading…
Reference in New Issue