web

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: May 16, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

README

web

web server

Documentation

Index

Constants

View Source
const (
	TypeOctetStream = "application/octet-stream"
	TypeForm        = "application/x-www-form-urlencoded"
	TypeJson        = "application/json"
	TypeXml         = "application/xml"
	TypeJpg         = "image/jpeg"
	TypePng         = "image/png"
)

Variables

This section is empty.

Functions

func File

func File(c *gin.Context, filePath, fileName string)

func JSON

func JSON(c *gin.Context, data any, err error)

func Redirect

func Redirect(c *gin.Context, location string)

Types

type CommonRsp

type CommonRsp struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    any    `json:"data,omitempty"`
}

type Config

type Config struct {
	Addr         string          `json:"addr" yaml:"addr" toml:"addr"`                            // addr, default :2233
	ReadTimeout  xtime.Duration  `json:"read_timeout" yaml:"read_timeout" toml:"read_timeout"`    // read_timeout, default 60s
	WriteTimeout xtime.Duration  `json:"write_timeout" yaml:"write_timeout" toml:"write_timeout"` // write_timeout, default 60s
	Debug        bool            `json:"debug" yaml:"debug" toml:"debug"`                         // is show log
	Limiter      *limiter.Config `json:"limiter" yaml:"limiter" toml:"limiter"`                   // interface limit
}

type GinEngine

type GinEngine struct {
	Gin *gin.Engine

	IgnoreReleaseLog bool
	// contains filtered or unexported fields
}

func InitGin

func InitGin(c *Config) *GinEngine

func (*GinEngine) AddExitHook

func (g *GinEngine) AddExitHook(hooks ...HookFunc) *GinEngine

添加 GinServer 进程退出时钩子函数

func (*GinEngine) AddShutdownHook

func (g *GinEngine) AddShutdownHook(hooks ...HookFunc) *GinEngine

添加 GinServer 服务关闭时的钩子函数

func (*GinEngine) Close

func (g *GinEngine) Close()

func (*GinEngine) Logger

func (g *GinEngine) Logger(ignoreRelease bool) gin.HandlerFunc

Logger

func (*GinEngine) Start

func (g *GinEngine) Start()

type HookFunc

type HookFunc func(c context.Context)

type HttpRsp

type HttpRsp[V any] struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    V      `json:"data,omitempty"`
}

type Pager

type Pager struct {
	PageNo   int `json:"page_no"`
	PageSize int `json:"page_size"`
}

func (Pager) Apply

func (p Pager) Apply(total int64, data any) any

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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