生成表结构,开始实现接口逻辑

This commit is contained in:
2025-05-29 16:22:48 +08:00
parent a048f45aa3
commit e8a8e36d61
21 changed files with 277 additions and 211 deletions

1
.gitignore vendored
View File

@ -16,3 +16,4 @@ manifest/output/
temp/
temp.yaml
bin
arenax

10
api/admin/v1/admin.go Normal file
View File

@ -0,0 +1,10 @@
package v1
import "github.com/gogf/gf/v2/frame/g"
type AdminInfoReq struct {
g.Meta `path:"/admin/info" method:"get" tags:"Admin" summary:"获取管理员信息"`
}
type AdminInfoRes struct {
g.Meta `mime:"application/json"`
}

View File

@ -1 +1,37 @@
package v1
import "github.com/gogf/gf/v2/frame/g"
type AdminLoginReq struct {
g.Meta `path:"/admin/login" method:"post" tags:"Admin" summary:"管理员登录"`
Username string `json:"username" v:"required" dc:"用户名"`
Password string `json:"password" v:"required" dc:"密码"`
}
type AdminLoginRes struct {
g.Meta `mime:"application/json"`
Token string `json:"token"`
}
type MerchantLoginReq struct {
g.Meta `path:"/merchant/login" method:"post" tags:"Merchant" summary:"商户登录"`
Usernaem string `json:"username" v:"required" dc:"用户名"`
Password string `json:"password" v:"required" dc:"密码"`
}
type MerchantLoginRes struct {
g.Meta `mime:"application/json"`
Token string `json:"token"`
}
type MerchantRegisterReq struct {
}
type MerchantRegisterRes struct {
}
type StoreLoginReq struct {
g.Meta `path:"/store/login" method:"post" tags:"Store" summary:"门店登录"`
Username string `json:"username" v:"required" dc:"用户名"`
Password string `json:"password" v:"required" dc:"密码"`
}
type StoreLoginRes struct {
g.Meta `mime:"application/json"`
Token string `json:"token"`
}

42
api/wx/v1/wx.go Normal file
View File

@ -0,0 +1,42 @@
package v1
import "github.com/gogf/gf/v2/frame/g"
type WeChatLoginReq struct {
g.Meta `path:"/wechat/login" method:"post" tags:"WeChat" summary:"获取微信二维码登录"`
UUID string `json:"uuid" v:"required" dc:"UUID"`
}
type WeChatLoginRes struct {
}
type WeChatEventReq struct {
g.Meta `path:"/wechat" method:"post" tags:"WeChat" summary:"微信订阅事件"`
ToUserName string `xml:"ToUserName" dc:"开发者微信号" json:"ToUserName,omitempty"`
FromUserName string `xml:"FromUserName" dc:"发送方账号OpenID" json:"FromUserName,omitempty"`
CreateTime int64 `xml:"CreateTime" dc:"消息创建时间" json:"CreateTime,omitempty"`
MsgType string `xml:"MsgType" dc:"消息类型" json:"MsgType,omitempty"`
Event string `xml:"Event" dc:"事件类型 subscribe | SCAN" json:"Event,omitempty"`
EventKey string `xml:"EventKey" dc:"事件KEY值" json:"EventKey,omitempty"`
Ticket string `xml:"Ticket" dc:"二维码ticket" json:"Ticket,omitempty"`
}
type WeChatEventRes struct {
}
type WeChatVertifyReq struct {
g.Meta `path:"/wechat" method:"Get" tags:"WeChat" summary:"微信服务器验证接口"`
Signature string `json:"signature" v:"required" dc:"微信签名"`
EchoStr string `json:"echostr" v:"required" dc:"随机字符串"`
Timestamp string `json:"timestamp" v:"required" dc:"时间戳"`
Nonce string `json:"nonce" v:"required" dc:"随机数"`
}
type WeChatVertifyRes struct {
}
type WeChatPollingReq struct {
g.Meta `path:"/wechat/polling" method:"post" tags:"WeChat" summary:"微信长轮询"`
UUID string `json:"uuid" v:"required" dc:"UUID"`
}
type WeChatPollingRes struct {
}

1
build_x86_64.sh Executable file
View File

@ -0,0 +1 @@
GOARCH=amd64 GOOS=linux CGO_ENABLED=0 go build -o ./arenax ./main.go

48
go.mod
View File

@ -1,48 +0,0 @@
module server
go 1.22
toolchain go1.24.2
require (
github.com/casbin/casbin/v2 v2.105.0
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.9.0
github.com/gogf/gf/contrib/nosql/redis/v2 v2.9.0
github.com/gogf/gf/v2 v2.9.0
github.com/golang-jwt/jwt/v5 v5.2.2
github.com/hailaz/gf-casbin-adapter/v2 v2.8.1
golang.org/x/crypto v0.30.0
)
require (
github.com/BurntSushi/toml v1.4.0 // indirect
github.com/bmatcuk/doublestar/v4 v4.6.1 // indirect
github.com/casbin/govaluate v1.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/clbanning/mxj/v2 v2.7.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/fatih/color v1.18.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-sql-driver/mysql v1.7.1 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/grokify/html-strip-tags-go v0.1.0 // indirect
github.com/magiconair/properties v1.8.9 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/redis/go-redis/v9 v9.7.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
go.opentelemetry.io/otel v1.32.0 // indirect
go.opentelemetry.io/otel/metric v1.32.0 // indirect
go.opentelemetry.io/otel/sdk v1.32.0 // indirect
go.opentelemetry.io/otel/trace v1.32.0 // indirect
golang.org/x/net v0.32.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

109
go.sum
View File

@ -1,109 +0,0 @@
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/bmatcuk/doublestar/v4 v4.6.1 h1:FH9SifrbvJhnlQpztAx++wlkk70QBf0iBWDwNy7PA4I=
github.com/bmatcuk/doublestar/v4 v4.6.1/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0=
github.com/casbin/casbin/v2 v2.105.0 h1:dLj5P6pLApBRat9SADGiLxLZjiDPvA1bsPkyV4PGx6I=
github.com/casbin/casbin/v2 v2.105.0/go.mod h1:Ee33aqGrmES+GNL17L0h9X28wXuo829wnNUnS0edAco=
github.com/casbin/govaluate v1.3.0 h1:VA0eSY0M2lA86dYd5kPPuNZMUD9QkWnOCnavGrw9myc=
github.com/casbin/govaluate v1.3.0/go.mod h1:G/UnbIjZk/0uMNaLwZZmFQrR72tYRZWQkO70si/iR7A=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/clbanning/mxj/v2 v2.7.0 h1:WA/La7UGCanFe5NpHF0Q3DNtnCsVoxbPKuyBNHWRyME=
github.com/clbanning/mxj/v2 v2.7.0/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn/Qo+ve2s=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.9.0 h1:1f7EeD0lfPHoXfaJDSL7cxRcSRelbsAKgF3MGXY+Uyo=
github.com/gogf/gf/contrib/drivers/mysql/v2 v2.9.0/go.mod h1:tToO1PjGkLIR+9DbJ0wrKicYma0H/EUHXOpwel6Dw+0=
github.com/gogf/gf/contrib/nosql/redis/v2 v2.9.0 h1:EEZqu1PNRSmm+7Cqm9A/8+ObgfbMzhE1ps9Z3LD7HgM=
github.com/gogf/gf/contrib/nosql/redis/v2 v2.9.0/go.mod h1:LHrxY+2IzNTHVTPG/s5yaz1VmXbj+CQ7Hr5SeVkHiTw=
github.com/gogf/gf/v2 v2.9.0 h1:semN5Q5qGjDQEv4620VzxcJzJlSD07gmyJ9Sy9zfbHk=
github.com/gogf/gf/v2 v2.9.0/go.mod h1:sWGQw+pLILtuHmbOxoe0D+0DdaXxbleT57axOLH2vKI=
github.com/golang-jwt/jwt/v5 v5.2.2 h1:Rl4B7itRWVtYIHFrSNd7vhTiz9UpLdi6gZhZ3wEeDy8=
github.com/golang-jwt/jwt/v5 v5.2.2/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/golang/mock v1.4.4 h1:l75CXGRSwbaYNpl/Z2X1XIIAMSCquvXgpVZDhwEIJsc=
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/grokify/html-strip-tags-go v0.1.0 h1:03UrQLjAny8xci+R+qjCce/MYnpNXCtgzltlQbOBae4=
github.com/grokify/html-strip-tags-go v0.1.0/go.mod h1:ZdzgfHEzAfz9X6Xe5eBLVblWIxXfYSQ40S/VKrAOGpc=
github.com/hailaz/gf-casbin-adapter/v2 v2.8.1 h1:ZFIlfQAYmrL2Fe6/dZz6vCA5hYK0NxhnoKMQpbklgqc=
github.com/hailaz/gf-casbin-adapter/v2 v2.8.1/go.mod h1:Jk91dRBZuMVjBMu2oQmqMRc6xuL5V+rzgHeFWvI+wlg=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/magiconair/properties v1.8.9 h1:nWcCbLq1N2v/cpNsy5WvQ37Fb+YElfq20WJ/a8RkpQM=
github.com/magiconair/properties v1.8.9/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/redis/go-redis/v9 v9.7.0 h1:HhLSs+B6O021gwzl+locl0zEDnyNkxMtf/Z3NNBMa9E=
github.com/redis/go-redis/v9 v9.7.0/go.mod h1:f6zhXITC7JUJIlPEiBOTXxJgPLdZcA93GewI7inzyWw=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
go.opentelemetry.io/otel v1.32.0 h1:WnBN+Xjcteh0zdk01SVqV55d/m62NJLJdIyb4y/WO5U=
go.opentelemetry.io/otel v1.32.0/go.mod h1:00DCVSB0RQcnzlwyTfqtxSm+DRr9hpYrHjNGiBHVQIg=
go.opentelemetry.io/otel/metric v1.32.0 h1:xV2umtmNcThh2/a/aCP+h64Xx5wsj8qqnkYZktzNa0M=
go.opentelemetry.io/otel/metric v1.32.0/go.mod h1:jH7CIbbK6SH2V2wE16W05BHCtIDzauciCRLoc/SyMv8=
go.opentelemetry.io/otel/sdk v1.32.0 h1:RNxepc9vK59A8XsgZQouW8ue8Gkb4jpWtJm9ge5lEG4=
go.opentelemetry.io/otel/sdk v1.32.0/go.mod h1:LqgegDBjKMmb2GC6/PrTnteJG39I8/vJCAP9LlJXEjU=
go.opentelemetry.io/otel/trace v1.32.0 h1:WIC9mYrXf8TmY/EXuULKc8hR17vE+Hjv2cssQDe03fM=
go.opentelemetry.io/otel/trace v1.32.0/go.mod h1:+i4rkvCraA+tG6AzwloGaCtkx53Fa+L+V8e9a7YvhT8=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.30.0 h1:RwoQn3GkWiMkzlX562cLB7OxWvjH1L8xutO2WoJcRoY=
golang.org/x/crypto v0.30.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI=
golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@ -5,6 +5,7 @@ import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/os/gcmd"
"server/internal/controller/auth"
"server/internal/middleware"
)
@ -16,16 +17,11 @@ var (
Func: func(ctx context.Context, parser *gcmd.Parser) (err error) {
s := g.Server()
s.Group("/", func(group *ghttp.RouterGroup) {
group.Middleware(ghttp.MiddlewareHandlerResponse)
group.Bind()
group.Group("/x", func(group *ghttp.RouterGroup) {
group.Middleware(
middleware.Auth,
middleware.Casbin,
middleware.Response,
group.Middleware(middleware.Response)
group.Middleware(ghttp.MiddlewareCORS)
group.Bind(
auth.NewV1(),
)
group.Bind()
})
})
s.Run()
return nil

View File

@ -0,0 +1,59 @@
package admin
import (
"context"
"server/internal/dao"
"server/internal/model"
"server/internal/model/do"
"server/internal/model/entity"
"server/internal/service"
"server/utility/ecode"
utility "server/utility/encrypt"
"server/utility/jwt"
)
type sAdmin struct {
}
func New() service.IAdmin {
return &sAdmin{}
}
func init() {
service.RegisterAdmin(New())
}
func (s *sAdmin) Login(ctx context.Context, in *model.AdminLoginIn) (out *model.LoginOut, err error) {
exist, err := dao.Admins.Ctx(ctx).Exist(do.Admins{Username: in.Username})
if err != nil {
return nil, ecode.Fail.Sub("查询管理员失败")
}
if !exist {
return nil, ecode.Params.Sub("该用户不存在")
}
var admin entity.Admins
if err := dao.Admins.Ctx(ctx).Where(do.Admins{Username: in.Username}).Scan(&admin); err != nil {
return nil, ecode.Fail.Sub("查询管理员失败")
}
if !utility.ComparePassword(admin.PasswordHash, in.Password) {
return nil, ecode.Auth.Sub("密码错误")
}
token, err := jwt.GenerateToken(&jwt.TokenIn{UserId: admin.Id, Permission: "admin"})
if err != nil {
return nil, ecode.Fail.Sub("生成token失败")
}
out = &model.LoginOut{
Token: token,
}
return
}
func (s *sAdmin) Info(ctx context.Context, in *model.AdminInfoIn) (out *model.AdminInfoOut, err error) {
exist, err := dao.Admins.Ctx(ctx).WherePri(in.Id).Exist()
if err != nil {
return nil, ecode.Fail.Sub("查询管理员失败")
}
if !exist {
return nil, ecode.Params.Sub("该用户不存在")
}
return
}

View File

@ -0,0 +1 @@
package merchantAdmin

View File

@ -0,0 +1 @@
package storeAdmin

View File

@ -0,0 +1 @@
package user

View File

@ -1,27 +1,28 @@
package middleware
import (
"github.com/gogf/gf/v2/net/ghttp"
"server/utility/ecode"
"server/utility/myCasbin"
)
// Casbin 是用于访问权限控制的中间件。
//
// 该中间件基于 Casbin 权限控制框架,校验当前用户是否有权访问指定的 URL 和请求方法。
// 用户权限从请求上下文中的 "permission" 字段获取,该字段通常由前置中间件(如 Auth注入。
//import (
// "github.com/gogf/gf/v2/net/ghttp"
// "server/utility/ecode"
// "server/utility/myCasbin"
//)
//
// 参数:
//
// r *ghttp.Request - 当前的 HTTP 请求对象,由框架自动传入
//
// 行为:
// - 如果权限验证未通过终止请求返回权限不足的错误ecode.Denied
// - 如果权限验证通过:继续执行后续中间件或处理逻辑。
func Casbin(r *ghttp.Request) {
permission := r.GetCtxVar("permission").String()
if !myCasbin.GetMyCasbin().HasPermission(permission, r.URL.Path, r.Method) {
Exit(r, ecode.Denied)
}
r.Middleware.Next()
}
//// Casbin 是用于访问权限控制的中间件。
////
//// 该中间件基于 Casbin 权限控制框架,校验当前用户是否有权访问指定的 URL 和请求方法
//// 用户权限从请求上下文中的 "permission" 字段获取,该字段通常由前置中间件(如 Auth注入。
////
//// 参数:
////
//// r *ghttp.Request - 当前的 HTTP 请求对象,由框架自动传入。
////
//// 行为:
//// - 如果权限验证未通过终止请求返回权限不足的错误ecode.Denied)。
//// - 如果权限验证通过:继续执行后续中间件或处理逻辑。
//func Casbin(r *ghttp.Request) {
// permission := r.GetCtxVar("permission").String()
// if !myCasbin.GetMyCasbin().HasPermission(permission, r.URL.Path, r.Method) {
// Exit(r, ecode.Denied)
// }
// r.Middleware.Next()
//}

View File

@ -1,11 +1,54 @@
package middleware
import (
"github.com/gogf/gf/v2/errors/gcode"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/net/ghttp"
"github.com/gogf/gf/v2/os/gctx"
"github.com/gogf/gf/v2/os/glog"
"github.com/gogf/gf/v2/util/gconv"
"net/http"
"server/utility/ecode"
)
// Response 统一响应中间件
func Response(r *ghttp.Request) {
r.Middleware.Next()
if r.Response.BufferLength() > 0 {
return
}
var (
msg string
err = r.GetError()
res = r.GetHandlerResponse()
code = gerror.Code(err)
)
glog.Debug(gctx.New(), "错误", err)
if err != nil {
if gconv.String(code.Detail()) != "customer" && code.Code() != 51 {
msg = ecode.Fail.Message()
} else if code.Code() == 51 {
msg = ecode.Params.Message()
} else {
msg = code.Message()
}
} else if r.Response.Status > 0 && r.Response.Status != http.StatusOK {
msg = http.StatusText(r.Response.Status)
switch r.Response.Status {
case http.StatusNotFound:
code = gcode.CodeNotFound
case http.StatusForbidden:
code = gcode.CodeNotAuthorized
default:
code = gcode.CodeUnknown
}
} else {
code = gcode.CodeOK
}
r.Response.WriteJson(ghttp.DefaultHandlerResponse{
Code: code.Code(),
Message: msg,
Data: res,
})
}

15
internal/model/admin.go Normal file
View File

@ -0,0 +1,15 @@
package model
type (
AdminLoginIn struct {
Username string
Password string
}
AdminInfoIn struct {
Id int
}
AdminInfoOut struct {
Token string
}
)

5
internal/model/common.go Normal file
View File

@ -0,0 +1,5 @@
package model
type LoginOut struct {
Token string
}

View File

@ -1,7 +1,7 @@
package packed
import (
_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
_ "github.com/gogf/gf/contrib/nosql/redis/v2"
_ "server/utility/myCasbin"
//_ "github.com/gogf/gf/contrib/drivers/mysql/v2"
//_ "github.com/gogf/gf/contrib/nosql/redis/v2"
_ "server/utility/wechat"
)

View File

@ -1,10 +1,12 @@
package main
import (
"github.com/gogf/gf/v2/os/gctx"
_ "server/internal/packed"
_ "server/internal/logic"
"server/internal/cmd"
_ "server/internal/packed"
"github.com/gogf/gf/v2/os/gctx"
)
func main() {

View File

@ -26,3 +26,10 @@ redis:
# Casbin model
casbin:
modelPath: "./manifest/config/rbac_model.conf"
#
wechat:
appId: "wx056fad20f1bd9110"
appSecret: "4269b5a2bb0274e805b43efb3fbd232a"
ticketExpire: 60
token: "arenax.com"

View File

@ -25,7 +25,7 @@ type (
// - Permission: 权限标识;
// - ExpireTime: token 过期时间(可选)。
TokenIn struct {
UserId int // 用户 ID
UserId int64 // 用户 ID
Permission string // 权限标识
ExpireTime time.Duration // 令牌有效期
}
@ -37,14 +37,14 @@ type (
// - Permission: 权限标识;
// - JTI: JWT 的唯一标识。
TokenOut struct {
UserId int // 用户 ID
UserId int64 // 用户 ID
Permission string // 权限标识
JTI string // JWT 唯一标识
}
// jwtClaims 自定义 JWT 的声明体结构,嵌入标准声明字段。
jwtClaims struct {
UserId int `json:"user_id"` // 用户 ID
UserId int64 `json:"user_id"` // 用户 ID
Permission string `json:"permission"` // 权限标识
JTI string `json:"jti"` // 唯一标识
jwt.RegisteredClaims

View File

@ -1,32 +1,34 @@
package utility
import (
"crypto/rand"
"fmt"
"math/rand"
"math/big"
"strings"
"time"
)
// GenerateUserID 根据传入的用户类型生成唯一的用户ID。
// 用户ID格式为<PREFIX>_<16位数字字符串>例如QQ_2025052712345678。
// 用户ID格式为<PREFIX>_<17位数字字符串>例如QQ_20250527123456789
// 前缀由 userType 参数指定(例如 "qq"、"wx"),自动转换为大写。
// 数字部分由当前时间戳随机数拼接而成,确保唯一性。
// 数字部分由当前时间戳毫秒级与4位加密随机数拼接而成,确保唯一性。
//
// 参数:
// - userType: 用户类型,如 "qq" 或 "wx"
//
// 返回值:
// - string: 格式为 <大写前缀>_<16位唯一数字> 的用户ID
// - string: 格式为 <大写前缀>_<17位唯一数字> 的用户ID
func GenerateUserID(userType string) string {
prefix := strings.ToUpper(userType)
timestamp := fmt.Sprintf("%d", time.Now().UnixNano())
core := timestamp[:12]
// 当前时间戳毫秒级长度为13位
timestamp := fmt.Sprintf("%d", time.Now().UnixNano()/1e6)
rand.Seed(time.Now().UnixNano())
suffix := fmt.Sprintf("%04d", rand.Intn(10000))
idNum := core + suffix
// 生成一个0~9999之间的随机数补齐4位
suffixNum, _ := rand.Int(rand.Reader, big.NewInt(10000))
suffix := fmt.Sprintf("%04d", suffixNum.Int64())
// 拼接最终ID
idNum := timestamp + suffix
return fmt.Sprintf("%s_%s", prefix, idNum)
}