用DDD分项目模块
This commit is contained in:
10
server/internal/ping/internal/config/config.go
Normal file
10
server/internal/ping/internal/config/config.go
Normal file
@@ -0,0 +1,10 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.1
|
||||
|
||||
package config
|
||||
|
||||
import "github.com/zeromicro/go-zero/rest"
|
||||
|
||||
type Config struct {
|
||||
rest.RestConf
|
||||
}
|
||||
31
server/internal/ping/internal/handler/ping/pinghandler.go
Normal file
31
server/internal/ping/internal/handler/ping/pinghandler.go
Normal file
@@ -0,0 +1,31 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.1
|
||||
|
||||
package ping
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/ping/internal/logic/ping"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/ping/internal/svc"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/ping/internal/types"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
func PingHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.PingReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := ping.NewPingLogic(r.Context(), svcCtx)
|
||||
resp, err := l.Ping(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
25
server/internal/ping/internal/handler/routes.go
Normal file
25
server/internal/ping/internal/handler/routes.go
Normal file
@@ -0,0 +1,25 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.9.1
|
||||
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
ping "github.com/JACKYMYPERSON/hldrCenter/internal/ping/internal/handler/ping"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/ping/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
|
||||
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/ping",
|
||||
Handler: ping.PingHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
33
server/internal/ping/internal/logic/ping/pinglogic.go
Normal file
33
server/internal/ping/internal/logic/ping/pinglogic.go
Normal file
@@ -0,0 +1,33 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.1
|
||||
|
||||
package ping
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/ping/internal/svc"
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/ping/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type PingLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewPingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PingLogic {
|
||||
return &PingLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *PingLogic) Ping(req *types.PingReq) (resp *types.PingResp, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
return
|
||||
}
|
||||
18
server/internal/ping/internal/svc/servicecontext.go
Normal file
18
server/internal/ping/internal/svc/servicecontext.go
Normal file
@@ -0,0 +1,18 @@
|
||||
// Code scaffolded by goctl. Safe to edit.
|
||||
// goctl 1.9.1
|
||||
|
||||
package svc
|
||||
|
||||
import (
|
||||
"github.com/JACKYMYPERSON/hldrCenter/internal/ping/internal/config"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
}
|
||||
}
|
||||
11
server/internal/ping/internal/types/types.go
Normal file
11
server/internal/ping/internal/types/types.go
Normal file
@@ -0,0 +1,11 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// goctl 1.9.1
|
||||
|
||||
package types
|
||||
|
||||
type PingReq struct {
|
||||
}
|
||||
|
||||
type PingResp struct {
|
||||
Msg string `json:"message"`
|
||||
}
|
||||
Reference in New Issue
Block a user