🎉 init

This commit is contained in:
landaiqing
2024-11-12 17:00:16 +08:00
commit 97ca3fc7b0
80 changed files with 26877 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
package config
import "github.com/zeromicro/go-zero/rest"
type Config struct {
rest.RestConf
Mysql struct {
Dsn string
}
}

View File

@@ -0,0 +1,43 @@
// Code generated by goctl. DO NOT EDIT.
// goctl 1.7.3
package handler
import (
"net/http"
"time"
user "schisandra-album-cloud-microservices/app/auth/internal/handler/user"
"schisandra-album-cloud-microservices/app/auth/internal/svc"
"github.com/zeromicro/go-zero/rest"
)
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
server.AddRoutes(
rest.WithMiddlewares(
[]rest.Middleware{serverCtx.I18nMiddleware, serverCtx.SecurityHeadersMiddleware},
[]rest.Route{
{
Method: http.MethodPost,
Path: "/login",
Handler: user.AccountLoginHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/phone_login",
Handler: user.PhoneLoginHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/reset_password",
Handler: user.ResetPasswordHandler(serverCtx),
},
}...,
),
rest.WithSignature(serverCtx.Config.Signature),
rest.WithPrefix("/api/auth/user"),
rest.WithTimeout(10000*time.Millisecond),
rest.WithMaxBytes(1048576),
)
}

View File

@@ -0,0 +1,28 @@
package user
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"schisandra-album-cloud-microservices/app/auth/internal/logic/user"
"schisandra-album-cloud-microservices/app/auth/internal/svc"
"schisandra-album-cloud-microservices/app/auth/internal/types"
)
func AccountLoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.AccountLoginRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := user.NewAccountLoginLogic(r.Context(), svcCtx)
resp, err := l.AccountLogin(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

View File

@@ -0,0 +1,28 @@
package user
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"schisandra-album-cloud-microservices/app/auth/internal/logic/user"
"schisandra-album-cloud-microservices/app/auth/internal/svc"
"schisandra-album-cloud-microservices/app/auth/internal/types"
)
func PhoneLoginHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.PhoneLoginRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := user.NewPhoneLoginLogic(r.Context(), svcCtx)
resp, err := l.PhoneLogin(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

View File

@@ -0,0 +1,28 @@
package user
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"schisandra-album-cloud-microservices/app/auth/internal/logic/user"
"schisandra-album-cloud-microservices/app/auth/internal/svc"
"schisandra-album-cloud-microservices/app/auth/internal/types"
)
func ResetPasswordHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.ResetPasswordRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := user.NewResetPasswordLogic(r.Context(), svcCtx)
resp, err := l.ResetPassword(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

View File

@@ -0,0 +1,30 @@
package user
import (
"context"
"schisandra-album-cloud-microservices/app/auth/internal/svc"
"schisandra-album-cloud-microservices/app/auth/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type AccountLoginLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewAccountLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AccountLoginLogic {
return &AccountLoginLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *AccountLoginLogic) AccountLogin(req *types.AccountLoginRequest) (resp *types.LoginResponse, err error) {
// todo: add your logic here and delete this line
return
}

View File

@@ -0,0 +1,30 @@
package user
import (
"context"
"schisandra-album-cloud-microservices/app/auth/internal/svc"
"schisandra-album-cloud-microservices/app/auth/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type PhoneLoginLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewPhoneLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PhoneLoginLogic {
return &PhoneLoginLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *PhoneLoginLogic) PhoneLogin(req *types.PhoneLoginRequest) (resp *types.LoginResponse, err error) {
// todo: add your logic here and delete this line
return
}

View File

@@ -0,0 +1,30 @@
package user
import (
"context"
"schisandra-album-cloud-microservices/app/auth/internal/svc"
"schisandra-album-cloud-microservices/app/auth/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type ResetPasswordLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewResetPasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ResetPasswordLogic {
return &ResetPasswordLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *ResetPasswordLogic) ResetPassword(req *types.ResetPasswordRequest) (resp string, err error) {
// todo: add your logic here and delete this line
return
}

View File

@@ -0,0 +1,19 @@
package middleware
import "net/http"
type I18nMiddleware struct {
}
func NewI18nMiddleware() *I18nMiddleware {
return &I18nMiddleware{}
}
func (m *I18nMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// TODO generate middleware implement function, delete after code implementation
// Passthrough to next handler if need
next(w, r)
}
}

View File

@@ -0,0 +1,21 @@
package middleware
import (
"net/http"
"schisandra-album-cloud-microservices/common/middleware"
)
type SecurityHeadersMiddleware struct {
}
func NewSecurityHeadersMiddleware() *SecurityHeadersMiddleware {
return &SecurityHeadersMiddleware{}
}
func (m *SecurityHeadersMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
middleware.SecurityHeadersMiddleware(w, r)
next(w, r)
}
}

View File

@@ -0,0 +1,26 @@
package svc
import (
"github.com/zeromicro/go-zero/rest"
"schisandra-album-cloud-microservices/app/auth/internal/config"
"schisandra-album-cloud-microservices/app/auth/internal/middleware"
"schisandra-album-cloud-microservices/common/core"
"schisandra-album-cloud-microservices/common/ent/gen/entschema"
)
type ServiceContext struct {
Config config.Config
I18nMiddleware rest.Middleware
SecurityHeadersMiddleware rest.Middleware
DB *entschema.Client
}
func NewServiceContext(c config.Config) *ServiceContext {
return &ServiceContext{
Config: c,
I18nMiddleware: middleware.NewI18nMiddleware().Handle,
SecurityHeadersMiddleware: middleware.NewSecurityHeadersMiddleware().Handle,
DB: core.InitMySQL(c.Mysql.Dsn),
}
}

View File

@@ -0,0 +1,34 @@
// Code generated by goctl. DO NOT EDIT.
// goctl 1.7.3
package types
type AccountLoginRequest struct {
Account string `json:"account"`
Password string `json:"password"`
AutoLogin bool `json:"auto_login"`
Angle int64 `json:"angle"`
Key string `json:"key"`
}
type LoginResponse struct {
AccessToken string `json:"access_token"`
UID string `json:"uid"`
Username string `json:"username,optional"`
Nickname string `json:"nickname"`
Avatar string `json:"avatar"`
Status int64 `json:"status"`
}
type PhoneLoginRequest struct {
Phone string `json:"phone"`
Captcha string `json:"captcha"`
AutoLogin bool `json:"auto_login"`
}
type ResetPasswordRequest struct {
Phone string `json:"phone"`
Captcha string `json:"captcha"`
Password string `json:"password"`
Repassword string `json:"repassword"`
}