httpx

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: AGPL-3.0 Imports: 13 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package httpServer provides the core HTTP server framework.

It combines Gin, Cobra, and service management (daemon) into a single entry point. Use Execute() to start the server with subcommands for run, install, and uninstall as a system service.

Modules register routes via SetRouter() in their init() functions, making integration pluggable without modifying core code.

Index

Constants

View Source
const (
	ResponseStatus_OK   = 0
	ResponseStatus_Fail = -1
)
View Source
const (
	MaxDataSize     = 100 * 1024 * 1024 // 100MB
	MaxStringLength = 10 * 1024 * 1024  // 10MB
)

Variables

View Source
var ResponseStatusMap = map[int]string{
	ResponseStatus_OK:   "ok",
	ResponseStatus_Fail: "fail",
}

Functions

func Execute

func Execute(serverName, serverShort string) error

func Request

func Request[T any](ctx *gin.Context) (req T, err error)

func Response

func Response(ctx *gin.Context, opts ...RespOption)

func SetBeforeRun

func SetBeforeRun(f func())

func SetRouter

func SetRouter(f func(root *gin.Engine))

Types

type PageInfo

type PageInfo struct {
	PageSize int64 `json:"page_size,omitempty"`
	Page     int64 `json:"page,omitempty"`
	Total    int64 `json:"total,omitempty"`
}

type Req

type Req[T any] struct {
	Data     T              `json:"data,omitempty"`
	Query    map[string]any `json:"query,omitempty"`
	PageInfo PageInfo       `json:"page_info,omitempty"`
}

func PageRequest

func PageRequest[T any](ctx *gin.Context) (req Req[T], err error)

type Resp

type Resp struct {
	Code     int       `json:"code"`
	Msg      string    `json:"msg"`
	Data     any       `json:"data,omitempty"`
	PageInfo *PageInfo `json:"page_info,omitempty"`
	T        int64     `json:"t"`
	// contains filtered or unexported fields
}

func (*Resp) SetResponseFunc

func (r *Resp) SetResponseFunc(fn func(*gin.Context))

SetResponseFunc 设置自定义响应函数,供子包选项使用

type RespOption

type RespOption func(*gin.Context, *Resp)

func AsAsciiJSON

func AsAsciiJSON() RespOption

func AsCustomerSet

func AsCustomerSet(fn func(c *gin.Context, r *Resp)) RespOption

func AsData

func AsData(contentType string) RespOption

func AsDataFromReader

func AsDataFromReader(contentType string, reader io.Reader) RespOption

func AsFile

func AsFile(filePath string) RespOption

func AsFileAttachment

func AsFileAttachment(filePath, fileName string) RespOption

func AsFileFromFS

func AsFileFromFS(filePath string, fs http.FileSystem) RespOption

func AsHTML

func AsHTML(templateName string) RespOption

func AsInnerJson

func AsInnerJson() RespOption

========== 格式选项 ==========

func AsJSON

func AsJSON() RespOption

func AsJSONP

func AsJSONP() RespOption

func AsPureJSON

func AsPureJSON() RespOption

func AsSecureJSON

func AsSecureJSON() RespOption

func AsString

func AsString() RespOption

func AsXML

func AsXML() RespOption

func AsYAML

func AsYAML() RespOption

func WithCode

func WithCode(code int) RespOption

func WithCustomerSet

func WithCustomerSet(fn func(c *gin.Context, r *Resp)) RespOption

func WithData

func WithData(data any) RespOption

func WithError

func WithError(err error, code ...int) RespOption

func WithHttpCode

func WithHttpCode(code int) RespOption

func WithMsg

func WithMsg(msg string) RespOption

func WithPageInfo

func WithPageInfo(p PageInfo) RespOption

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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