httpserver

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LogFormat

func LogFormat(r *Request, content any) string

LogFormat 日志格式

func MiddlewareHandlerCORS

func MiddlewareHandlerCORS(r *Request)

MiddlewareHandlerCORS HTTP 中间件 - CORS 处理

func MiddlewareHandlerResponse

func MiddlewareHandlerResponse(r *Request)

MiddlewareHandlerResponse HTTP 中间件 - 响应处理

Types

type Group

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

Group 路由组

func (*Group) ALL

func (r *Group) ALL(prefix string, object any)

ALL 注册 ALL 路由

func (*Group) Bind

func (r *Group) Bind(method Method, prefix string, object any)

Bind 注册路由

func (*Group) CONNECT

func (r *Group) CONNECT(prefix string, object any)

CONNECT 注册 CONNECT 路由

func (*Group) DELETE

func (r *Group) DELETE(prefix string, object any)

DELETE 注册 DELETE 路由

func (*Group) GET

func (r *Group) GET(prefix string, object any)

GET 注册 GET 路由

func (*Group) HEAD

func (r *Group) HEAD(prefix string, object any)

HEAD 注册 HEAD 路由

func (*Group) OPTIONS

func (r *Group) OPTIONS(prefix string, object any)

OPTIONS 注册 OPTIONS 路由

func (*Group) PATCH

func (r *Group) PATCH(prefix string, object any)

PATCH 注册 PATCH 路由

func (*Group) POST

func (r *Group) POST(prefix string, object any)

POST 注册 POST 路由

func (*Group) PUT

func (r *Group) PUT(prefix string, object any)

PUT 注册 PUT 路由

func (*Group) TRACE

func (r *Group) TRACE(prefix string, object any)

TRACE 注册 TRACE 路由

func (*Group) Use

func (r *Group) Use(middleware ...Middleware)

Use 添加中间件

type HTTPRouter

type HTTPRouter struct {
	kunit.Unit
	// contains filtered or unexported fields
}

HTTPRouter HTTP 路由

func (*HTTPRouter) AddBind

func (r *HTTPRouter) AddBind(bindObject ...any)

AddBind 添加路由绑定对象

func (*HTTPRouter) AddMiddleware

func (r *HTTPRouter) AddMiddleware(middleware ...Middleware)

AddMiddleware 添加中间件

func (*HTTPRouter) AddStaticPath

func (r *HTTPRouter) AddStaticPath(uri, file string)

AddStaticPath 添加静态文件路由

func (*HTTPRouter) Group

func (r *HTTPRouter) Group(prefix string, f func(group *Group))

Group 创建路由组

func (*HTTPRouter) Register

func (h *HTTPRouter) Register(s server.Server)

Register 注册路由

func (*HTTPRouter) SetGroupsPrefix

func (r *HTTPRouter) SetGroupsPrefix(prefix string)

SetGroupsPrefix 设置路由组前缀

func (*HTTPRouter) SetStaticRoot

func (r *HTTPRouter) SetStaticRoot(root string)

SetStaticRoot 设置静态文件根目录

type HTTPServer

type HTTPServer struct {
	kunit.Unit
	Serv   *ghttp.Server
	Port   int           // 端口
	Router server.Router // 路由
}

HTTPServer HTTP服务

func NewHTTPServer

func NewHTTPServer() *HTTPServer

New 创建实例

func (*HTTPServer) Init

func (h *HTTPServer) Init(ctx kctx.Context) kerr.Error

Set 设置服务

func (*HTTPServer) Setup

func (s *HTTPServer) Setup(ctx kctx.Context) kerr.Error

Register 注册服务包

func (*HTTPServer) Start

func (h *HTTPServer) Start(ctx kctx.Context) kerr.Error

Start 启动服务

func (*HTTPServer) Stop

func (h *HTTPServer) Stop(ctx kctx.Context) kerr.Error

Stop 停止服务

type Meta

type Meta g.Meta

type Method

type Method string

Method HTTP 方法

const (

	// HTTP 方法
	GET     Method = "GET"
	POST    Method = "POST"
	PUT     Method = "PUT"
	DELETE  Method = "DELETE"
	HEAD    Method = "HEAD"
	OPTIONS Method = "OPTIONS"
	TRACE   Method = "TRACE"
	CONNECT Method = "CONNECT"
	PATCH   Method = "PATCH"
	ALL     Method = "ALL"
)

type Middleware

type Middleware = func(r *Request)

Middleware HTTP 中间件

type Request

type Request = ghttp.Request

Request HTTP 请求

Jump to

Keyboard shortcuts

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