web

package
v0.0.0-...-1babd1e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 18, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const LOGGER_KEY = "APP_WIDE_LOGGER"

Variables

View Source
var Module = fx.Module("web",
	fx.Provide(
		GetValidator,
		func(config WebConfig, log *zap.Logger) *JwtHandler {
			return NewJwtHandler(config.GetJwtSecret(), log)
		},
		NewPostController,
		NewAccountController,
		NewSiteController,
	),

	fx.Invoke(
		SetupValidation,
		SetupRouter,
	))

Functions

func CtxLoggerMidleware

func CtxLoggerMidleware(log *zap.Logger) gin.HandlerFunc

func GetLogger

func GetLogger(ctx context.Context) *zap.Logger

func GetRole

func GetRole(ctx context.Context) domain.AccountRole

func GetUID

func GetUID(ctx context.Context) int

func GetUserOp

func GetUserOp(ctx context.Context) perm.ResId

func GetValidator

func GetValidator() *validator.Validate

func RegisterGinLogger

func RegisterGinLogger(ctx *gin.Context, log *zap.Logger)

func RegisterLogger

func RegisterLogger(ctx context.Context, log *zap.Logger) context.Context

func RequiredAuthMiddware

func RequiredAuthMiddware() gin.HandlerFunc

func SetupRouter

func SetupRouter(router *gin.Engine,
	jwt *JwtHandler,
	account *AccountController,
	site *SiteController,
	post *PostController)

func SetupValidation

func SetupValidation(validator *validator.Validate)

func ValidateEnum

func ValidateEnum(fl validator.FieldLevel) bool

Types

type Account

type Account struct {
	ID       int
	Username string
	Email    string
}

Account DTO

type AccountController

type AccountController struct {
	// contains filtered or unexported fields
}

func NewAccountController

func NewAccountController(usecase *usecase.Account, log *zap.Logger, perm *perm.Perm, jwt *JwtHandler) *AccountController

func (*AccountController) HandleGet

func (c *AccountController) HandleGet(ctx *gin.Context)

func (*AccountController) HandleList

func (c *AccountController) HandleList(ctx *gin.Context)

func (*AccountController) HandleLogin

func (c *AccountController) HandleLogin(ctx *gin.Context)

create account

func (*AccountController) HandlePost

func (c *AccountController) HandlePost(ctx *gin.Context)

create account

func (*AccountController) ToDto

func (c *AccountController) ToDto(acc *domain.Account) *Account

type AccountCreateRequest

type AccountCreateRequest struct {
	Email    string             `json:"email" binding:"required"`
	Username string             `json:"username" binding:"required"`
	Role     domain.AccountRole `json:"role" binding:"enum"`
	Password string             `json:"password" binding:"required"`
}

type AccountLoginRequest

type AccountLoginRequest struct {
	Username string `json:"username" binding:"required"`
	Password string `json:"password" binding:"required"`
}

type AuthClaims

type AuthClaims struct {
	jwt.RegisteredClaims
	Role string
}

type AuthToken

type AuthToken struct {
	Token   *jwt.Token
	Claims  *AuthClaims
	Expired bool
}

func GetToken

func GetToken(ctx context.Context) *AuthToken

type JwtHandler

type JwtHandler struct {
	// contains filtered or unexported fields
}

func NewJwtHandler

func NewJwtHandler(secret string, log *zap.Logger) *JwtHandler

func (*JwtHandler) Parse

func (j *JwtHandler) Parse(tokenStr string) (*jwt.Token, *AuthClaims, error)

func (*JwtHandler) ParseMiddleware

func (j *JwtHandler) ParseMiddleware() gin.HandlerFunc

func (*JwtHandler) Signed

func (j *JwtHandler) Signed(uid int, role string) (string, error)

type LoginResult

type LoginResult struct {
	Token string `json:"token"`
}

type Post

type Post struct {
	Id      int
	Content string
}

Post DTO

type PostController

type PostController struct {
	// contains filtered or unexported fields
}

func NewPostController

func NewPostController(usecase *usecase.Post, log *zap.SugaredLogger) *PostController

func (*PostController) HandleDelete

func (c *PostController) HandleDelete(ctx *gin.Context)

func (*PostController) HandleGet

func (c *PostController) HandleGet(ctx *gin.Context)

func (*PostController) HandleList

func (c *PostController) HandleList(ctx *gin.Context)

func (*PostController) HandlePost

func (c *PostController) HandlePost(ctx *gin.Context)

func (*PostController) ToDto

func (c *PostController) ToDto(post *domain.Post) *Post

type PostCreateRequest

type PostCreateRequest struct {
	Content string `json:"content" binding:"required"`
	SiteId  int    `json:"siteId" binding:"required"`
}

type PostListRequest

type PostListRequest struct {
	Page     int `form:"page"`
	PageSize int `form:"pageSize"  binding:"required"`
	SiteId   int `form:"siteId"`
}

type Site

type Site struct {
	ID   int
	Name string
}

Site DTO

type SiteController

type SiteController struct {
	// contains filtered or unexported fields
}

func NewSiteController

func NewSiteController(usecase *usecase.Site, log *zap.Logger, perm *perm.Perm) *SiteController

func (*SiteController) HandleList

func (c *SiteController) HandleList(ctx *gin.Context)

func (*SiteController) ToDto

func (c *SiteController) ToDto(site *domain.Site) *Site

type WebConfig

type WebConfig interface {
	GetJwtSecret() string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL