新设计
This commit is contained in:
7
home-user-auth/internal/config/config.go
Normal file
7
home-user-auth/internal/config/config.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package config
|
||||
|
||||
import "github.com/zeromicro/go-zero/rest"
|
||||
|
||||
type Config struct {
|
||||
rest.RestConf
|
||||
}
|
||||
22
home-user-auth/internal/handler/routes.go
Normal file
22
home-user-auth/internal/handler/routes.go
Normal file
@@ -0,0 +1,22 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"home-user-auth/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest"
|
||||
)
|
||||
|
||||
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
server.AddRoutes(
|
||||
[]rest.Route{
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/user/fonts",
|
||||
Handler: UserFontsHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
28
home-user-auth/internal/handler/userfontshandler.go
Normal file
28
home-user-auth/internal/handler/userfontshandler.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"home-user-auth/internal/logic"
|
||||
"home-user-auth/internal/svc"
|
||||
"home-user-auth/internal/types"
|
||||
)
|
||||
|
||||
func UserFontsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.Request
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := logic.NewUserFontsLogic(r.Context(), svcCtx)
|
||||
resp, err := l.UserFonts(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
29
home-user-auth/internal/logic/userfontslogic.go
Normal file
29
home-user-auth/internal/logic/userfontslogic.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"home-user-auth/internal/svc"
|
||||
"home-user-auth/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UserFontsLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewUserFontsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserFontsLogic {
|
||||
return &UserFontsLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UserFontsLogic) UserFonts(req *types.Request) (resp *types.Response, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
return
|
||||
}
|
||||
24
home-user-auth/internal/svc/servicecontext.go
Normal file
24
home-user-auth/internal/svc/servicecontext.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package svc
|
||||
|
||||
import (
|
||||
"home-user-auth/internal/config"
|
||||
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
DB *gorm.DB
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
db, err := gorm.Open(mysql.Open(c.DataSourceName), &gorm.Config{})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
DB: db,
|
||||
}
|
||||
}
|
||||
18
home-user-auth/internal/types/types.go
Normal file
18
home-user-auth/internal/types/types.go
Normal file
@@ -0,0 +1,18 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
package types
|
||||
|
||||
type Request struct {
|
||||
Name string `form:"name"` // parameters are auto validated
|
||||
}
|
||||
|
||||
type FsFonts struct {
|
||||
Title string `json:"title" gorm:"column:title"`
|
||||
LinuxFontname string `json:"linux_fontname" gorm:"column:linux_fontname"`
|
||||
Link string `json:"link" gorm:"link"`
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"msg"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
Reference in New Issue
Block a user