zero构建

This commit is contained in:
2025-10-05 18:28:59 +08:00
parent 934f77323c
commit 1e6c2e88a1
19 changed files with 81 additions and 503 deletions

View File

@@ -1,3 +0,0 @@
Name: ping-api
Host: 0.0.0.0
Port: 8888

View File

@@ -7,12 +7,11 @@ 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 {
func PingHandler() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.PingReq
if err := httpx.Parse(r, &req); err != nil {
@@ -20,7 +19,7 @@ func PingHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return
}
l := ping.NewPingLogic(r.Context(), svcCtx)
l := ping.NewPingLogic(r.Context())
resp, err := l.Ping(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)

View File

@@ -1,10 +0,0 @@
// 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
}

View File

@@ -1,25 +0,0 @@
// 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),
},
},
)
}

View File

@@ -6,7 +6,6 @@ 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"
@@ -14,20 +13,19 @@ import (
type PingLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
ctx context.Context
}
func NewPingLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PingLogic {
func NewPingLogic(ctx context.Context) *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
return &types.PingResp{
Msg: "success",
}, nil
}

View File

@@ -1,18 +0,0 @@
// 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,
}
}

View File

@@ -1,34 +0,0 @@
// Code scaffolded by goctl. Safe to edit.
// goctl 1.9.1
package main
import (
"flag"
"fmt"
"github.com/JACKYMYPERSON/hldrCenter/internal/ping/internal/config"
"github.com/JACKYMYPERSON/hldrCenter/internal/ping/internal/handler"
"github.com/JACKYMYPERSON/hldrCenter/internal/ping/internal/svc"
"github.com/zeromicro/go-zero/core/conf"
"github.com/zeromicro/go-zero/rest"
)
var configFile = flag.String("f", "etc/ping-api.yaml", "the config file")
func main() {
flag.Parse()
var c config.Config
conf.MustLoad(*configFile, &c)
server := rest.MustNewServer(c.RestConf)
defer server.Stop()
ctx := svc.NewServiceContext(c)
handler.RegisterHandlers(server, ctx)
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
server.Start()
}