webx

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2025 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

* @Author: hugo * @Date: 2024-04-19 17:54 * @LastEditors: hugo * @LastEditTime: 2024-07-31 17:50 * @FilePath: \gotox\webx\handler.go * @Description: * * Copyright (c) 2024 by hugo, All Rights Reserved.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetLogger

func SetLogger(l logx.Logger)

// 自定义的logger,建议实例化赋予

func Wrap

func Wrap(fn func(ctx *gin.Context) (Response, error)) gin.HandlerFunc

func WrapBind

func WrapBind[T any](fn func(ctx *gin.Context, req T) (Response, error)) gin.HandlerFunc

func WrapBindQueryAndBody

func WrapBindQueryAndBody[Q any, B any](fn func(ctx *gin.Context, query Q, body B) (Response, error)) gin.HandlerFunc

func WrapPage

func WrapPage(fn func(ctx *gin.Context, page, pageSize int) (Response, error)) gin.HandlerFunc

Types

type ErrMsg

type ErrMsg struct {
	Code    int
	Message string
}

type Handler

type Handler interface {
	// PublicAPI(server *gin.Engine)
	// PrivateAPI(server *gin.Engine)
	RegisterRouter(*gin.Engine)
}

type Response

type Response struct {
	// Code 响应的业务错误码。0表示业务执行成功,非0表示业务执行失败。
	Code int `json:"code"`
	// Message 响应的参考消息。前端可使用msg来做提示
	Message string `json:"msg"`
	// Data 响应的具体数据
	Data any `json:"data"`
}

Response 统一的响应格式

func ResponseErr

func ResponseErr(err ErrMsg) Response

func ResponseSuccess

func ResponseSuccess(data any) Response

Directories

Path Synopsis
middleware
auth
* @Author: hugo * @Date: 2024-04-28 16:51 * @LastEditors: hugo * @LastEditTime: 2024-09-10 16:02 * @FilePath: \gotox\webx\middleware\auth\auth.go * @Description: * * Copyright (c) 2024 by hugo, All Rights Reserved.
* @Author: hugo * @Date: 2024-04-28 16:51 * @LastEditors: hugo * @LastEditTime: 2024-09-10 16:02 * @FilePath: \gotox\webx\middleware\auth\auth.go * @Description: * * Copyright (c) 2024 by hugo, All Rights Reserved.

Jump to

Keyboard shortcuts

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