check params

This commit is contained in:
2026-08-06 22:20:28 +08:00
parent 9d5b507634
commit e7e3aa12c3
15 changed files with 1465 additions and 0 deletions
+51
View File
@@ -0,0 +1,51 @@
package config
import "github.com/zeromicro/go-zero/zrpc"
type Config struct {
zrpc.RpcServerConf
Nacos NacosConf
Mysql MysqlConf
BizRedis RedisConf
AppLog LogConf
}
type NacosConf struct {
Hosts []string
NamespaceId string `json:",optional"`
Group string `json:",optional"`
RegisterIP string `json:",optional"`
}
type MysqlConf struct {
Host string
Port int
User string
Password string
Database string
Charset string `json:",default=utf8mb4"`
Prefix string `json:",optional"`
ReadHost string `json:",optional"`
ReadPort int `json:",optional"`
ReadUser string `json:",optional"`
ReadPassword string `json:",optional"`
ReadDatabase string `json:",optional"`
}
type RedisConf struct {
Host string
Port int `json:",default=6379"`
Password string `json:",optional"`
DB int `json:",optional"`
}
type LogConf struct {
Path string `json:",default=logs"`
InfoFile string `json:",default=info.log"`
ErrorFile string `json:",default=error.log"`
FatalFile string `json:",default=fatal.log"`
MaxSize int `json:",default=100"`
MaxBackups int `json:",default=10"`
MaxAge int `json:",default=30"`
}
+35
View File
@@ -0,0 +1,35 @@
package logic
import (
"admin/validator"
"context"
"admin/admin"
"admin/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
validateService "pkg.local/validate"
)
type AddLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddLogic {
return &AddLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *AddLogic) Add(in *admin.AddRequest) (*admin.Response, error) {
var req validator.AdminAddValidator
if resp := validateService.ValidateFromProto(in, &req); resp != "" {
return &admin.Response{Code: 111, Msg: resp}, nil
}
return &admin.Response{}, nil
}
+32
View File
@@ -0,0 +1,32 @@
package logic
import (
"context"
"admin/admin"
"admin/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type EditLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewEditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EditLogic {
return &EditLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *EditLogic) Edit(in *admin.EditRequest) (*admin.Response, error) {
// todo: add your logic here and delete this line
return &admin.Response{
Msg: in.Name + " " + in.Pwd,
}, nil
}
+30
View File
@@ -0,0 +1,30 @@
package logic
import (
"context"
"admin/admin"
"admin/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type StatusLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *StatusLogic {
return &StatusLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *StatusLogic) Status(in *admin.StatusRequest) (*admin.Response, error) {
// todo: add your logic here and delete this line
return &admin.Response{}, nil
}
+39
View File
@@ -0,0 +1,39 @@
// Code generated by goctl. DO NOT EDIT.
// goctl 1.10.2
// Source: admin.proto
package server
import (
"context"
"admin/admin"
"admin/internal/logic"
"admin/internal/svc"
)
type AdminServer struct {
svcCtx *svc.ServiceContext
admin.UnimplementedAdminServer
}
func NewAdminServer(svcCtx *svc.ServiceContext) *AdminServer {
return &AdminServer{
svcCtx: svcCtx,
}
}
func (s *AdminServer) Add(ctx context.Context, in *admin.AddRequest) (*admin.Response, error) {
l := logic.NewAddLogic(ctx, s.svcCtx)
return l.Add(in)
}
func (s *AdminServer) Edit(ctx context.Context, in *admin.EditRequest) (*admin.Response, error) {
l := logic.NewEditLogic(ctx, s.svcCtx)
return l.Edit(in)
}
func (s *AdminServer) Status(ctx context.Context, in *admin.StatusRequest) (*admin.Response, error) {
l := logic.NewStatusLogic(ctx, s.svcCtx)
return l.Status(in)
}
+21
View File
@@ -0,0 +1,21 @@
package svc
import (
"admin/internal/config"
"gorm.io/gorm"
)
type ServiceContext struct {
Config config.Config
DB *gorm.DB
Prefix string
}
func NewServiceContext(c config.Config, db *gorm.DB) *ServiceContext {
return &ServiceContext{
Config: c,
DB: db,
Prefix: c.Mysql.Prefix,
}
}