Compare commits
No commits in common. "main" and "v0.0.49" have entirely different histories.
|
@ -8,6 +8,7 @@ type Base struct {
|
||||||
BindIP string `yaml:"BindIP"` // 绑定IP
|
BindIP string `yaml:"BindIP"` // 绑定IP
|
||||||
Addr string `yaml:"Addr"`
|
Addr string `yaml:"Addr"`
|
||||||
OnMicroService bool `yaml:"OnMicroService"`
|
OnMicroService bool `yaml:"OnMicroService"`
|
||||||
|
LoginUrl string `yaml:"LoginUrl"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DBConf struct {
|
type DBConf struct {
|
||||||
|
|
|
@ -1,58 +0,0 @@
|
||||||
package data
|
|
||||||
|
|
||||||
import (
|
|
||||||
"sync"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
// Cache
|
|
||||||
CacheMapFloat *MapFloat
|
|
||||||
)
|
|
||||||
|
|
||||||
// lock
|
|
||||||
type MapFloat struct {
|
|
||||||
sync.RWMutex
|
|
||||||
Data map[string]float64
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewMapFloat() *MapFloat {
|
|
||||||
return &MapFloat{
|
|
||||||
Data: make(map[string]float64),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *MapFloat) All() map[string]float64 {
|
|
||||||
c.RLock()
|
|
||||||
defer c.RUnlock()
|
|
||||||
|
|
||||||
return c.Data
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *MapFloat) Get(key string) float64 {
|
|
||||||
c.RLock()
|
|
||||||
defer c.RUnlock()
|
|
||||||
|
|
||||||
vals, ok := c.Data[key]
|
|
||||||
if !ok {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
return vals
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *MapFloat) Set(key string, val float64) {
|
|
||||||
c.Lock()
|
|
||||||
defer c.Unlock()
|
|
||||||
c.Data[key] = val
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *MapFloat) Keys() (keys []string) {
|
|
||||||
c.RLock()
|
|
||||||
defer c.RUnlock()
|
|
||||||
|
|
||||||
for k, _ := range c.Data {
|
|
||||||
keys = append(keys, k)
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
|
@ -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
|
|
||||||
}
|
|
|
@ -15,18 +15,13 @@ var (
|
||||||
|
|
||||||
// standard error code ,start:110
|
// standard error code ,start:110
|
||||||
var (
|
var (
|
||||||
ErrEmpty = NewError(110, "Data Is Empty")
|
ErrEmpty = NewError(110, "Data Is Empty")
|
||||||
ErrRequestParse = NewError(111, "Request Parse Fail")
|
ErrRequestParse = NewError(111, "Request Parse Fail")
|
||||||
ErrRequestMust = NewError(112, "Request Params Required")
|
ErrRequestMust = NewError(112, "Request Params Required")
|
||||||
ErrPermission = NewError(113, "Permission Denied")
|
ErrPermission = NewError(113, "Permission Denied")
|
||||||
ErrJsonUnmarshal = NewError(114, "Json Unmarshal Fail")
|
ErrJsonUnmarshal = NewError(114, "Json Unmarshal Fail")
|
||||||
ErrJsonMarshal = NewError(115, "Json Marshal Fail")
|
ErrJsonMarshal = NewError(115, "Json Marshal Fail")
|
||||||
ErrInternal = NewError(116, "Internal Server Error")
|
ErrInternal = NewError(116, "Internal Server Error")
|
||||||
ErrPassword = NewError(117, "Password Incorrect")
|
|
||||||
ErrAccountNotFound = NewError(118, "Account Not Found")
|
|
||||||
ErrAccountDisabled = NewError(119, "Account Disabled")
|
|
||||||
ErrDisabled = NewError(120, "Status Disabled")
|
|
||||||
ErrRecordNotFound = NewError(121, "Record Not Found")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// jwt error code ,start:130
|
// jwt error code ,start:130
|
||||||
|
|
|
@ -8,29 +8,29 @@ import (
|
||||||
var Response Reply
|
var Response Reply
|
||||||
|
|
||||||
type Reply struct {
|
type Reply struct {
|
||||||
Code int32 `json:"code"`
|
Code int `json:"code"`
|
||||||
Message string `json:"message"`
|
Msg string `json:"msg"`
|
||||||
Result any `json:"result"`
|
Data any `json:"data"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (reply *Reply) Success(ctx *gin.Context, data any) {
|
func (reply *Reply) Success(ctx *gin.Context, data any) {
|
||||||
reply.Code = 0
|
reply.Code = 200
|
||||||
reply.Result = data
|
reply.Data = data
|
||||||
reply.Message = ""
|
reply.Msg = ""
|
||||||
if data == nil {
|
if data == nil {
|
||||||
reply.Result = ""
|
reply.Data = ""
|
||||||
}
|
}
|
||||||
ctx.JSON(200, reply)
|
ctx.JSON(200, reply)
|
||||||
}
|
}
|
||||||
func (reply *Reply) Error(ctx *gin.Context, err error) {
|
func (reply *Reply) Error(ctx *gin.Context, err error) {
|
||||||
reply.Code = 500
|
reply.Code = 500
|
||||||
reply.Result = ""
|
reply.Data = ""
|
||||||
// Status code defaults to 500
|
// Status code defaults to 500
|
||||||
e, ok := status.FromError(err)
|
e, ok := status.FromError(err)
|
||||||
if ok {
|
if ok {
|
||||||
reply.Code = int32(e.Code())
|
reply.Code = int(e.Code())
|
||||||
}
|
}
|
||||||
reply.Message = e.Message()
|
reply.Msg = e.Message()
|
||||||
|
|
||||||
// Send error
|
// Send error
|
||||||
ctx.JSON(200, reply)
|
ctx.JSON(200, reply)
|
||||||
|
|
|
@ -58,8 +58,8 @@ var (
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
const (
|
const (
|
||||||
signKey = "1F36659EC27CFFF849E068EA80B1A4CA"
|
signKey = "8E853B589944FF7A56BEF02AAA51D6F4"
|
||||||
LICENCE_KEY = "BLOCKS_KEY"
|
LICENCE_KEY = "TRAIN_LICENCE_KEY"
|
||||||
)
|
)
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -69,13 +69,13 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func WatchCheckLicence(licPath, licName string) {
|
func WatchCheckLicence(licPath, licName string) {
|
||||||
utils.SetInterval(func() {
|
for {
|
||||||
if CheckLicence(licPath, licName) == false {
|
if CheckLicence(licPath, licName) == false {
|
||||||
log.Println("授权文件失效,请重新部署授权文件:", licPath)
|
log.Println("授权文件失效,请重新部署授权文件:", licPath)
|
||||||
os.Exit(99)
|
os.Exit(99)
|
||||||
}
|
}
|
||||||
|
time.Sleep(time.Hour * 1)
|
||||||
}, time.Hour*1)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -2,6 +2,7 @@ package middleware
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
@ -32,14 +33,14 @@ func JwtAuth(redis *redis.RedisClient) gin.HandlerFunc {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 从redis 获取token,判断当前redis 是否为空
|
// 从redis 获取token,判断当前redis 是否为空
|
||||||
// tokenKey := fmt.Sprintf("%d-%s-%s", claims.ID, claims.Role, "token")
|
tokenKey := fmt.Sprintf("%d-%s-%s", claims.ID, claims.Role, "token")
|
||||||
// redisToken := redis.Client.Get(redis.Ctx, tokenKey)
|
redisToken := redis.Client.Get(redis.Ctx, tokenKey)
|
||||||
// if redisToken.Val() == "" {
|
if redisToken.Val() == "" {
|
||||||
// log.Println("redis异常", "Token status unauthorized")
|
log.Println("redis异常", "Token status unauthorized")
|
||||||
// c.JSON(http.StatusUnauthorized, gin.H{"error": "Token status unauthorized"})
|
c.JSON(http.StatusUnauthorized, gin.H{"error": "Token status unauthorized"})
|
||||||
// c.Abort()
|
c.Abort()
|
||||||
// return
|
return
|
||||||
// }
|
}
|
||||||
|
|
||||||
// 将解析后的 Token 存储到上下文中
|
// 将解析后的 Token 存储到上下文中
|
||||||
c.Set("Auth", claims)
|
c.Set("Auth", claims)
|
||||||
|
|
|
@ -15,5 +15,4 @@ var (
|
||||||
Type_Delete string = "delete"
|
Type_Delete string = "delete"
|
||||||
Type_Query string = "query"
|
Type_Query string = "query"
|
||||||
Type_Other string = "other"
|
Type_Other string = "other"
|
||||||
Type_Create string = "create"
|
|
||||||
)
|
)
|
||||||
|
|
36
types/db.go
36
types/db.go
|
@ -10,42 +10,42 @@ type (
|
||||||
|
|
||||||
// sql options
|
// sql options
|
||||||
SqlOptions struct {
|
SqlOptions struct {
|
||||||
MaxIdleConns int `gorm:"column:max_idle_conns;" json:"max_idle_conns"`
|
MaxIdleConns int
|
||||||
MaxOpenConns int `gorm:"column:max_open_conns;" json:"max_open_conns"`
|
MaxOpenConns int
|
||||||
ConnMaxLifetime time.Duration
|
ConnMaxLifetime time.Duration
|
||||||
|
|
||||||
LogStdout bool `gorm:"column:log_stdout;" json:"log_stdout"`
|
LogStdout bool
|
||||||
Debug bool `gorm:"column:debug;" json:"debug"`
|
Debug bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// standard ID,Identity definition.
|
// standard ID,Identity definition.
|
||||||
Std_IDIdentity struct {
|
Std_IDIdentity struct {
|
||||||
ID uint `gorm:"column:id;primarykey;" json:"id"`
|
ID uint `gorm:"primarykey;" json:"id"`
|
||||||
Identity string `gorm:"column:identity;type:varchar(36);uniqueIndex;" json:"identity"` // 唯一标识,24位NanoID,36位为ULID
|
Identity string `gorm:"column:identity;type:varchar(36);uniqueIndex;" json:"identity"` // 唯一标识,24位NanoID,36位为ULID
|
||||||
}
|
}
|
||||||
|
|
||||||
// standard ID,Created,Updated,Deleted definition.
|
// standard ID,Created,Updated,Deleted definition.
|
||||||
Std_IICUDS struct {
|
Std_IICUDS struct {
|
||||||
ID uint `gorm:"column:id;primarykey;" json:"id"`
|
ID uint `gorm:"primarykey;" json:"id"`
|
||||||
Identity string `gorm:"column:identity;type:varchar(36);uniqueIndex;" json:"identity"` // 唯一标识,24位NanoID,36位为ULID
|
Identity string `gorm:"column:identity;type:varchar(36);uniqueIndex;" json:"identity"` // 唯一标识,24位NanoID,36位为ULID
|
||||||
CreatedAt time.Time `gorm:"column:created_at;" json:"created_at"`
|
CreatedAt time.Time `gorm:"" json:"created_at"`
|
||||||
UpdatedAt time.Time `gorm:"column:updated_at;" json:"updated_at"`
|
UpdatedAt time.Time `gorm:"" json:"updated_at"`
|
||||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;index;" json:"deleted_at"`
|
DeletedAt gorm.DeletedAt `gorm:"index;" json:"deleted_at"`
|
||||||
Status int8 `gorm:"column:status;default:0;index;" json:"status"` // 状态:默认为0,-1禁止,1为正常
|
Status int8 `gorm:"default:0;index;" json:"status"` // 状态:默认为0,-1禁止,1为正常
|
||||||
}
|
}
|
||||||
|
|
||||||
// standard ID,Identity,Created,Updated,Deleted,Status definition.
|
// standard ID,Identity,Created,Updated,Deleted,Status definition.
|
||||||
Std_ICUD struct {
|
Std_ICUD struct {
|
||||||
ID uint `gorm:"column:id;primarykey;" json:"id"`
|
ID uint `gorm:"primarykey;" json:"id"`
|
||||||
CreatedAt time.Time `gorm:"column:created_at;" json:"created_at"`
|
CreatedAt time.Time `gorm:"" json:"created_at"`
|
||||||
UpdatedAt time.Time `gorm:"column:updated_at;" json:"updated_at"`
|
UpdatedAt time.Time `gorm:"" json:"updated_at"`
|
||||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;index;" json:"deleted_at"`
|
DeletedAt gorm.DeletedAt `gorm:"index;" json:"deleted_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// standard ID,Created definition.
|
// standard ID,Created definition.
|
||||||
Std_IdCreated struct {
|
Std_IdCreated struct {
|
||||||
ID uint `gorm:"column:id;primarykey;" json:"id"`
|
ID uint `gorm:"primarykey;" json:"id"`
|
||||||
CreatedAt time.Time `gorm:"column:created_at;" json:"created_at"`
|
CreatedAt time.Time `gorm:"" json:"created_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// standard PassportID,PassportIdentity definition.
|
// standard PassportID,PassportIdentity definition.
|
||||||
|
@ -62,7 +62,7 @@ type (
|
||||||
|
|
||||||
// standard ID definition.
|
// standard ID definition.
|
||||||
Std_ID struct {
|
Std_ID struct {
|
||||||
ID uint `gorm:"column:id;primarykey;" json:"id"`
|
ID uint `gorm:"primarykey;" json:"id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// standard Identity definition.
|
// standard Identity definition.
|
||||||
|
@ -72,6 +72,6 @@ type (
|
||||||
|
|
||||||
// standard Status definition.
|
// standard Status definition.
|
||||||
Std_Status struct {
|
Std_Status struct {
|
||||||
Status int64 `gorm:"column:status;default:0;index;" json:"status"` // 状态:默认为0,-1禁止,1为正常
|
Status int64 `gorm:"default:0;index;" json:"status"` // 状态:默认为0,-1禁止,1为正常
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
10
utils/net.go
10
utils/net.go
|
@ -2,7 +2,6 @@ package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
@ -122,15 +121,6 @@ func HttpGet(url string) ([]byte, error) {
|
||||||
return body, err
|
return body, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func HttpPostJSON(url string, header map[string]string, data map[string]any) ([]byte, error) {
|
|
||||||
bytes, err := json.Marshal(data)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return HttpPost(url, header, bytes)
|
|
||||||
}
|
|
||||||
|
|
||||||
func HttpPost(url string, header map[string]string, data []byte) ([]byte, error) {
|
func HttpPost(url string, header map[string]string, data []byte) ([]byte, error) {
|
||||||
var err error
|
var err error
|
||||||
reader := bytes.NewBuffer(data)
|
reader := bytes.NewBuffer(data)
|
||||||
|
|
Loading…
Reference in New Issue