captcha

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewModule

func NewModule(redisClient *redis.Client, config *frameCaptcha.Config) core.Module

NewModule 创建验证码模块

Types

type Handler

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

Handler HTTP 处理器

func NewHandler

func NewHandler(service frameCaptcha.Service, config *frameCaptcha.Config) *Handler

NewHandler 创建处理器

func (*Handler) Generate

func (h *Handler) Generate(w http.ResponseWriter, r *http.Request)

Generate godoc @Summary 生成验证码 @Description 生成新的验证码挑战 @Tags captcha @Accept json @Produce json @Param type query string false "验证码类型 (math|image)" default(math) @Success 200 {object} responder.Response @Failure 429 {object} responder.Response @Router /captcha [get]

func (*Handler) Verify

func (h *Handler) Verify(w http.ResponseWriter, r *http.Request)

Verify godoc @Summary 验证验证码 @Description 验证验证码答案 @Tags captcha @Accept json @Produce json @Param request body VerifyRequest true "验证请求" @Success 200 {object} responder.Response @Failure 400 {object} responder.Response @Failure 429 {object} responder.Response @Router /captcha/verify [post]

type Module

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

Module 验证码模块

func (*Module) GetService

func (m *Module) GetService() frameCaptcha.Service

GetService 返回 captcha 服务(用于注入到其他模块)

func (*Module) Name

func (m *Module) Name() string

Name 返回模块名称

func (*Module) RegisterPrivateRoutes

func (m *Module) RegisterPrivateRoutes(router chi.Router)

RegisterPrivateRoutes 注册私有路由(验证码模块不需要私有路由)

func (*Module) RegisterPublicRoutes

func (m *Module) RegisterPublicRoutes(router chi.Router)

RegisterPublicRoutes 注册公共路由

type VerifyRequest

type VerifyRequest struct {
	ID     string `json:"id" validate:"required"`     // 验证码 ID
	Answer string `json:"answer" validate:"required"` // 用户答案
}

VerifyRequest 验证请求

Jump to

Keyboard shortcuts

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