上传gm模块补充
This commit is contained in:
parent
c6c2b5daae
commit
3af54fdb14
@ -1,9 +1,14 @@
|
|||||||
package gin
|
package gin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"reflect"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"go_dreamfactory/lego/sys/gin/engine"
|
"go_dreamfactory/lego/sys/gin/engine"
|
||||||
|
"go_dreamfactory/lego/utils/crypto/md5"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ISys interface {
|
type ISys interface {
|
||||||
@ -71,3 +76,41 @@ func Static(relativePath string, root string) engine.IRoutes {
|
|||||||
func StaticFS(relativePath string, fs http.FileSystem) engine.IRoutes {
|
func StaticFS(relativePath string, fs http.FileSystem) engine.IRoutes {
|
||||||
return defsys.StaticFS(relativePath, fs)
|
return defsys.StaticFS(relativePath, fs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//签名接口
|
||||||
|
func ParamSign(key string, param map[string]interface{}) (sign string) {
|
||||||
|
var keys []string
|
||||||
|
for k, _ := range param {
|
||||||
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
sort.Strings(keys)
|
||||||
|
builder := strings.Builder{}
|
||||||
|
for _, v := range keys {
|
||||||
|
builder.WriteString(v)
|
||||||
|
builder.WriteString("=")
|
||||||
|
switch reflect.TypeOf(param[v]).Kind() {
|
||||||
|
case reflect.Int,
|
||||||
|
reflect.Int8,
|
||||||
|
reflect.Int16,
|
||||||
|
reflect.Int32,
|
||||||
|
reflect.Int64,
|
||||||
|
reflect.Uint,
|
||||||
|
reflect.Uint8,
|
||||||
|
reflect.Uint16,
|
||||||
|
reflect.Uint32,
|
||||||
|
reflect.Uint64,
|
||||||
|
reflect.Uintptr,
|
||||||
|
reflect.Float32,
|
||||||
|
reflect.Float64:
|
||||||
|
builder.WriteString(fmt.Sprintf("%d", param[v]))
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
builder.WriteString(fmt.Sprintf("%s", param[v]))
|
||||||
|
break
|
||||||
|
}
|
||||||
|
builder.WriteString("&")
|
||||||
|
}
|
||||||
|
builder.WriteString("key=" + key)
|
||||||
|
sign = md5.MD5EncToLower(builder.String())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
13
lego/utils/crypto/base64/base64.go
Normal file
13
lego/utils/crypto/base64/base64.go
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package base64
|
||||||
|
|
||||||
|
import "encoding/base64"
|
||||||
|
|
||||||
|
///编码
|
||||||
|
func EncodeToString(src []byte) string {
|
||||||
|
return base64.StdEncoding.EncodeToString(src)
|
||||||
|
}
|
||||||
|
|
||||||
|
///解码
|
||||||
|
func DecodeString(s string) ([]byte, error) {
|
||||||
|
return base64.StdEncoding.DecodeString(s)
|
||||||
|
}
|
47
lego/utils/crypto/md5/md5.go
Normal file
47
lego/utils/crypto/md5/md5.go
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
package md5
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/md5"
|
||||||
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
MD5加密
|
||||||
|
*/
|
||||||
|
|
||||||
|
//MD5加密 大写
|
||||||
|
func MD5EncToUpper(str string) string {
|
||||||
|
h := md5.New()
|
||||||
|
h.Write([]byte(str))
|
||||||
|
return strings.ToUpper(hex.EncodeToString(h.Sum(nil)))
|
||||||
|
}
|
||||||
|
|
||||||
|
//MD5加密 小写
|
||||||
|
func MD5EncToLower(str string) string {
|
||||||
|
h := md5.New()
|
||||||
|
h.Write([]byte(str))
|
||||||
|
return strings.ToLower(hex.EncodeToString(h.Sum(nil)))
|
||||||
|
}
|
||||||
|
|
||||||
|
//参数签名
|
||||||
|
func ParamSign(param map[string]interface{}, key string) (orsign, sign string) {
|
||||||
|
a := sort.StringSlice{}
|
||||||
|
for k, _ := range param {
|
||||||
|
a = append(a, k)
|
||||||
|
}
|
||||||
|
sort.Sort(a)
|
||||||
|
orsign = ""
|
||||||
|
for _, k := range a {
|
||||||
|
switch param[k].(type) { //只签名基础数据
|
||||||
|
case bool, byte, int8, int16, uint16, int32, uint32, int, int64, uint64, float64, float32, string:
|
||||||
|
orsign = orsign + fmt.Sprintf("%s=%v&", k, param[k])
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
orsign = orsign + fmt.Sprintf("key=%s", key)
|
||||||
|
sign = MD5EncToLower(orsign)
|
||||||
|
return
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package web
|
package gm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go_dreamfactory/lego/core"
|
"go_dreamfactory/lego/core"
|
||||||
@ -11,16 +11,16 @@ import (
|
|||||||
*/
|
*/
|
||||||
type Api_Comp struct {
|
type Api_Comp struct {
|
||||||
cbase.ModuleCompBase
|
cbase.ModuleCompBase
|
||||||
options *Options //模块参数
|
options *Options //模块参数
|
||||||
moduleWeb *Web //当前模块对象
|
module *GM //当前模块对象
|
||||||
gin gin.ISys //gin 框架 web的热门框架
|
gin gin.ISys //gin 框架 web的热门框架
|
||||||
}
|
}
|
||||||
|
|
||||||
//组件初始化接口 启动web服务 并注册api
|
//组件初始化接口 启动web服务 并注册api
|
||||||
func (this *Api_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
func (this *Api_Comp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
||||||
err = this.ModuleCompBase.Init(service, module, comp, options)
|
err = this.ModuleCompBase.Init(service, module, comp, options)
|
||||||
this.options = options.(*Options)
|
this.options = options.(*Options)
|
||||||
this.moduleWeb = module.(*Web)
|
this.module = module.(*GM)
|
||||||
this.gin, err = gin.NewSys(gin.SetListenPort(this.options.Port))
|
this.gin, err = gin.NewSys(gin.SetListenPort(this.options.Port))
|
||||||
this.gin.POST("/register", this.Register)
|
this.gin.POST("/register", this.Register)
|
||||||
this.gin.GET("/serverlist", this.ServerList)
|
this.gin.GET("/serverlist", this.ServerList)
|
46
modules/gm/api_createnotify.go
Normal file
46
modules/gm/api_createnotify.go
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
package gm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go_dreamfactory/lego/sys/gin"
|
||||||
|
"go_dreamfactory/lego/sys/gin/engine"
|
||||||
|
"go_dreamfactory/lego/sys/log"
|
||||||
|
"go_dreamfactory/pb"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CreateNotifyReq struct {
|
||||||
|
pb.DBSystemNotify
|
||||||
|
Sign string `json:"sign"`
|
||||||
|
}
|
||||||
|
|
||||||
|
//服务列表
|
||||||
|
func (this *Api_Comp) CreateNotify(c *engine.Context) {
|
||||||
|
req := &CreateNotifyReq{}
|
||||||
|
c.BindJSON(&req)
|
||||||
|
defer log.Debugf("CreateNotify:%+v", req)
|
||||||
|
var (
|
||||||
|
code pb.ErrorCode
|
||||||
|
msg string
|
||||||
|
data interface{}
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
c.JSON(http.StatusOK, &Respond{Code: code, Message: msg, Data: data})
|
||||||
|
if sign := gin.ParamSign(this.options.Key, map[string]interface{}{"Title": req.Title, "Ctime": req.Ctime, "Rtime": req.Rtime}); sign != req.Sign {
|
||||||
|
log.Errorf("LoginByCaptchaReq SignError sgin:%s", sign)
|
||||||
|
code = pb.ErrorCode_SignError
|
||||||
|
msg = pb.GetErrorCodeMsg(code)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if len(req.Title) == 0 {
|
||||||
|
code = pb.ErrorCode_ReqParameterError
|
||||||
|
msg = pb.GetErrorCodeMsg(code)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = this.module.modelNotify.CreateSystemNotify(&req.DBSystemNotify); err != nil {
|
||||||
|
log.Errorf("LoginByCaptchaReq CreateSystemNotify err:%v", err)
|
||||||
|
code = pb.ErrorCode_DBError
|
||||||
|
msg = pb.GetErrorCodeMsg(code)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
msg = pb.GetErrorCodeMsg(code)
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package web
|
package gm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go_dreamfactory/lego/sys/gin/engine"
|
"go_dreamfactory/lego/sys/gin/engine"
|
||||||
@ -13,7 +13,7 @@ func (this *Api_Comp) Register(c *engine.Context) {
|
|||||||
rsp := &pb.UserRegisterResp{}
|
rsp := &pb.UserRegisterResp{}
|
||||||
err := c.BindJSON(&req)
|
err := c.BindJSON(&req)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err := this.moduleWeb.modelUser.User_Create(&pb.DBUser{
|
err := this.module.modelUser.User_Create(&pb.DBUser{
|
||||||
Binduid: req.Account,
|
Binduid: req.Account,
|
||||||
Sid: req.Sid,
|
Sid: req.Sid,
|
||||||
})
|
})
|
@ -1,4 +1,4 @@
|
|||||||
package web
|
package gm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go_dreamfactory/lego/sys/gin/engine"
|
"go_dreamfactory/lego/sys/gin/engine"
|
||||||
@ -7,7 +7,7 @@ import (
|
|||||||
|
|
||||||
//服务列表
|
//服务列表
|
||||||
func (this *Api_Comp) ServerList(c *engine.Context) {
|
func (this *Api_Comp) ServerList(c *engine.Context) {
|
||||||
conf := this.moduleWeb.configure.getServerListConf()
|
conf := this.module.configure.getServerListConf()
|
||||||
|
|
||||||
c.JSON(http.StatusOK, conf)
|
c.JSON(http.StatusOK, conf)
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package web
|
package gm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
9
modules/gm/core.go
Normal file
9
modules/gm/core.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package gm
|
||||||
|
|
||||||
|
import "go_dreamfactory/pb"
|
||||||
|
|
||||||
|
type Respond struct {
|
||||||
|
Code pb.ErrorCode `json:"code"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
Data interface{} `json:"data"`
|
||||||
|
}
|
42
modules/gm/modelNotify.go
Normal file
42
modules/gm/modelNotify.go
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
package gm
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go_dreamfactory/lego/core"
|
||||||
|
"go_dreamfactory/lego/sys/log"
|
||||||
|
"go_dreamfactory/modules"
|
||||||
|
"go_dreamfactory/pb"
|
||||||
|
|
||||||
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
|
"go.mongodb.org/mongo-driver/x/bsonx"
|
||||||
|
)
|
||||||
|
|
||||||
|
///论坛 数据组件
|
||||||
|
type modelNotifyComp struct {
|
||||||
|
modules.MCompModel
|
||||||
|
module *GM
|
||||||
|
}
|
||||||
|
|
||||||
|
//组件初始化接口
|
||||||
|
func (this *modelNotifyComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, opt core.IModuleOptions) (err error) {
|
||||||
|
this.MCompModel.Init(service, module, comp, opt)
|
||||||
|
this.module = module.(*GM)
|
||||||
|
this.TableName = "notify"
|
||||||
|
//创建uid索引
|
||||||
|
this.DB.CreateIndex(core.SqlTable(this.TableName), mongo.IndexModel{
|
||||||
|
Keys: bsonx.Doc{{Key: "uid", Value: bsonx.Int32(1)}},
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//创建系统公告
|
||||||
|
func (this *modelNotifyComp) CreateSystemNotify(notify *pb.DBSystemNotify) (err error) {
|
||||||
|
if _, err = this.DB.InsertOne(core.SqlTable(this.TableName), notify); err != nil {
|
||||||
|
log.Errorf("CreateSystemNotify err:%v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = this.Redis.HSet(this.TableName, notify.Id, notify); err != nil {
|
||||||
|
log.Errorf("CreateSystemNotify err:%v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package web
|
package gm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go_dreamfactory/comm"
|
"go_dreamfactory/comm"
|
||||||
@ -9,40 +9,41 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
模块名:web
|
模块名:gm
|
||||||
描述:为服务集群提供一些http服务接口 方便测试和后期运维实现
|
描述:提供管理员相关的http接口
|
||||||
开发:李伟
|
开发:李伟
|
||||||
*/
|
*/
|
||||||
func NewModule() core.IModule {
|
func NewModule() core.IModule {
|
||||||
m := new(Web)
|
m := new(GM)
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
type Web struct {
|
type GM struct {
|
||||||
cbase.ModuleBase
|
cbase.ModuleBase
|
||||||
options *Options
|
options *Options
|
||||||
api_comp *Api_Comp //提供weba pi服务的组件
|
api_comp *Api_Comp //提供weba pi服务的组件
|
||||||
modelUser *user.ModelUser
|
modelUser *user.ModelUser
|
||||||
configure *configureComp
|
modelNotify *modelNotifyComp
|
||||||
|
configure *configureComp
|
||||||
}
|
}
|
||||||
|
|
||||||
//模块名
|
//模块名
|
||||||
func (this *Web) GetType() core.M_Modules {
|
func (this *GM) GetType() core.M_Modules {
|
||||||
return comm.ModuleWeb
|
return comm.ModuleWeb
|
||||||
}
|
}
|
||||||
|
|
||||||
//模块自定义参数
|
//模块自定义参数
|
||||||
func (this *Web) NewOptions() (options core.IModuleOptions) {
|
func (this *GM) NewOptions() (options core.IModuleOptions) {
|
||||||
return new(Options)
|
return new(Options)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Web) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
|
func (this *GM) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
|
||||||
err = this.ModuleBase.Init(service, module, options)
|
err = this.ModuleBase.Init(service, module, options)
|
||||||
this.options = options.(*Options)
|
this.options = options.(*Options)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Web) OnInstallComp() {
|
func (this *GM) OnInstallComp() {
|
||||||
this.ModuleBase.OnInstallComp()
|
this.ModuleBase.OnInstallComp()
|
||||||
this.api_comp = this.RegisterComp(new(Api_Comp)).(*Api_Comp)
|
this.api_comp = this.RegisterComp(new(Api_Comp)).(*Api_Comp)
|
||||||
this.modelUser = this.RegisterComp(new(user.ModelUser)).(*user.ModelUser)
|
this.modelUser = this.RegisterComp(new(user.ModelUser)).(*user.ModelUser)
|
@ -1,4 +1,4 @@
|
|||||||
package web
|
package gm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go_dreamfactory/lego/utils/mapstructure"
|
"go_dreamfactory/lego/utils/mapstructure"
|
||||||
@ -7,6 +7,7 @@ import (
|
|||||||
type (
|
type (
|
||||||
Options struct {
|
Options struct {
|
||||||
Port int
|
Port int
|
||||||
|
Key string
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
@ -6,6 +6,7 @@ import (
|
|||||||
"go_dreamfactory/lego/sys/log"
|
"go_dreamfactory/lego/sys/log"
|
||||||
"go_dreamfactory/modules"
|
"go_dreamfactory/modules"
|
||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/go-redis/redis/v8"
|
"github.com/go-redis/redis/v8"
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
@ -56,10 +57,13 @@ func (this *modelNotifyComp) GetFullNotify() (result []*pb.DBSystemNotify, err e
|
|||||||
}
|
}
|
||||||
if len(notifys) > 0 {
|
if len(notifys) > 0 {
|
||||||
n := 0
|
n := 0
|
||||||
|
now := time.Now().Unix()
|
||||||
result = make([]*pb.DBSystemNotify, len(notifys))
|
result = make([]*pb.DBSystemNotify, len(notifys))
|
||||||
for _, v := range notifys {
|
for _, v := range notifys {
|
||||||
result[n] = v
|
if now >= v.Rtime {
|
||||||
n++
|
result[n] = v
|
||||||
|
n++
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
@ -99,7 +99,7 @@ func (this *SCompGateRoute) ReceiveMsg(ctx context.Context, args *pb.AgentMessag
|
|||||||
l := runtime.Stack(buf, false)
|
l := runtime.Stack(buf, false)
|
||||||
reply.Code = pb.ErrorCode_Exception
|
reply.Code = pb.ErrorCode_Exception
|
||||||
reply.ErrorMessage = fmt.Sprintf("%v: %s", r, buf[:l])
|
reply.ErrorMessage = fmt.Sprintf("%v: %s", r, buf[:l])
|
||||||
log.Errorf("HandleUserMsg:[%s-%s] err:%s", args.MainType, args.SubType, reply.ErrorMessage)
|
log.Errorf("[Handle Api]:[%s-%s] err:%s", args.MainType, args.SubType, reply.ErrorMessage)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
method := fmt.Sprintf("%s.%s", args.MainType, args.SubType)
|
method := fmt.Sprintf("%s.%s", args.MainType, args.SubType)
|
||||||
|
Loading…
Reference in New Issue
Block a user