feat: docker mysql and redis

This commit is contained in:
zzw
2026-08-06 13:43:52 +08:00
parent 58242dee8d
commit c37cedc664
26 changed files with 1349 additions and 129 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"`
}
+30
View File
@@ -0,0 +1,30 @@
package logic
import (
"context"
"order/internal/svc"
"order/order"
"github.com/zeromicro/go-zero/core/logx"
)
type PingLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewPingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PingLogic {
return &PingLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *PingLogic) Ping(in *order.Request) (*order.Response, error) {
// todo: add your logic here and delete this line
return &order.Response{}, nil
}
+29
View File
@@ -0,0 +1,29 @@
// Code generated by goctl. DO NOT EDIT.
// goctl 1.10.1
// Source: order.proto
package server
import (
"context"
"order/internal/logic"
"order/internal/svc"
"order/order"
)
type OrderServer struct {
svcCtx *svc.ServiceContext
order.UnimplementedOrderServer
}
func NewOrderServer(svcCtx *svc.ServiceContext) *OrderServer {
return &OrderServer{
svcCtx: svcCtx,
}
}
func (s *OrderServer) Ping(ctx context.Context, in *order.Request) (*order.Response, error) {
l := logic.NewPingLogic(ctx, s.svcCtx)
return l.Ping(in)
}
+21
View File
@@ -0,0 +1,21 @@
package svc
import (
"order/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,
}
}