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
- Variables
- func Execute(serverName, serverShort string) error
- func Request[T any](ctx *gin.Context) (req T, err error)
- func Response(ctx *gin.Context, opts ...RespOption)
- func SetBeforeRun(f func())
- func SetRouter(f func(root *gin.Engine))
- type PageInfo
- type Req
- type Resp
- type RespOption
- func AsAsciiJSON() RespOption
- func AsCustomerSet(fn func(c *gin.Context, r *Resp)) RespOption
- func AsData(contentType string) RespOption
- func AsDataFromReader(contentType string, reader io.Reader) RespOption
- func AsFile(filePath string) RespOption
- func AsFileAttachment(filePath, fileName string) RespOption
- func AsFileFromFS(filePath string, fs http.FileSystem) RespOption
- func AsHTML(templateName string) RespOption
- func AsInnerJson() RespOption
- func AsJSON() RespOption
- func AsJSONP() RespOption
- func AsPureJSON() RespOption
- func AsSecureJSON() RespOption
- func AsString() RespOption
- func AsXML() RespOption
- func AsYAML() RespOption
- func WithCode(code int) RespOption
- func WithCustomerSet(fn func(c *gin.Context, r *Resp)) RespOption
- func WithData(data any) RespOption
- func WithError(err error, code ...int) RespOption
- func WithHttpCode(code int) RespOption
- func WithMsg(msg string) RespOption
- func WithPageInfo(p PageInfo) RespOption
Constants ¶
const ( ResponseStatus_OK = 0 ResponseStatus_Fail = -1 )
const ( MaxDataSize = 100 * 1024 * 1024 // 100MB MaxStringLength = 10 * 1024 * 1024 // 10MB )
Variables ¶
var ResponseStatusMap = map[int]string{ ResponseStatus_OK: "ok", ResponseStatus_Fail: "fail", }
Functions ¶
func Response ¶
func Response(ctx *gin.Context, opts ...RespOption)
func SetBeforeRun ¶
func SetBeforeRun(f func())
Types ¶
type Req ¶
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 ¶
SetResponseFunc 设置自定义响应函数,供子包选项使用
type RespOption ¶
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 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