ghttp

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2025 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusContinue           = http.StatusContinue           // RFC 9110, 15.2.1
	StatusSwitchingProtocols = http.StatusSwitchingProtocols // RFC 9110, 15.2.2
	StatusProcessing         = http.StatusProcessing         // RFC 2518, 10.1
	StatusEarlyHints         = http.StatusEarlyHints         // RFC 8297

	StatusOK                   = http.StatusOK                   // RFC 9110, 15.3.1
	StatusCreated              = http.StatusCreated              // RFC 9110, 15.3.2
	StatusAccepted             = http.StatusAccepted             // RFC 9110, 15.3.3
	StatusNonAuthoritativeInfo = http.StatusNonAuthoritativeInfo // RFC 9110, 15.3.4
	StatusNoContent            = http.StatusNoContent            // RFC 9110, 15.3.5
	StatusResetContent         = http.StatusResetContent         // RFC 9110, 15.3.6
	StatusPartialContent       = http.StatusPartialContent       // RFC 9110, 15.3.7
	StatusMultiStatus          = http.StatusMultiStatus          // RFC 4918, 11.1
	StatusAlreadyReported      = http.StatusAlreadyReported      // RFC 5842, 7.1
	StatusIMUsed               = http.StatusIMUsed               // RFC 3229, 10.4.1

	StatusMultipleChoices   = http.StatusMultipleChoices   // RFC 9110, 15.4.1
	StatusMovedPermanently  = http.StatusMovedPermanently  // RFC 9110, 15.4.2
	StatusFound             = http.StatusFound             // RFC 9110, 15.4.3
	StatusSeeOther          = http.StatusSeeOther          // RFC 9110, 15.4.4
	StatusNotModified       = http.StatusNotModified       // RFC 9110, 15.4.5
	StatusUseProxy          = http.StatusUseProxy          // RFC 9110, 15.4.6
	StatusTemporaryRedirect = http.StatusTemporaryRedirect // RFC 9110, 15.4.8
	StatusPermanentRedirect = http.StatusPermanentRedirect // RFC 9110, 15.4.9

	StatusBadRequest                   = http.StatusBadRequest                   // RFC 9110, 15.5.1
	StatusUnauthorized                 = http.StatusUnauthorized                 // RFC 9110, 15.5.2
	StatusPaymentRequired              = http.StatusPaymentRequired              // RFC 9110, 15.5.3
	StatusForbidden                    = http.StatusForbidden                    // RFC 9110, 15.5.4
	StatusNotFound                     = http.StatusNotFound                     // RFC 9110, 15.5.5
	StatusMethodNotAllowed             = http.StatusMethodNotAllowed             // RFC 9110, 15.5.6
	StatusNotAcceptable                = http.StatusNotAcceptable                // RFC 9110, 15.5.7
	StatusProxyAuthRequired            = http.StatusProxyAuthRequired            // RFC 9110, 15.5.8
	StatusRequestTimeout               = http.StatusRequestTimeout               // RFC 9110, 15.5.9
	StatusConflict                     = http.StatusConflict                     // RFC 9110, 15.5.10
	StatusGone                         = http.StatusGone                         // RFC 9110, 15.5.11
	StatusLengthRequired               = http.StatusLengthRequired               // RFC 9110, 15.5.12
	StatusPreconditionFailed           = http.StatusPreconditionFailed           // RFC 9110, 15.5.13
	StatusRequestEntityTooLarge        = http.StatusRequestEntityTooLarge        // RFC 9110, 15.5.14
	StatusRequestURITooLong            = http.StatusRequestURITooLong            // RFC 9110, 15.5.15
	StatusUnsupportedMediaType         = http.StatusUnsupportedMediaType         // RFC 9110, 15.5.16
	StatusRequestedRangeNotSatisfiable = http.StatusRequestedRangeNotSatisfiable // RFC 9110, 15.5.17
	StatusExpectationFailed            = http.StatusExpectationFailed            // RFC 9110, 15.5.18
	StatusTeapot                       = http.StatusTeapot                       // RFC 9110, 15.5.19 (Unused)
	StatusMisdirectedRequest           = http.StatusMisdirectedRequest           // RFC 9110, 15.5.20
	StatusUnprocessableEntity          = http.StatusUnprocessableEntity          // RFC 9110, 15.5.21
	StatusLocked                       = http.StatusLocked                       // RFC 4918, 11.3
	StatusFailedDependency             = http.StatusFailedDependency             // RFC 4918, 11.4
	StatusTooEarly                     = http.StatusTooEarly                     // RFC 8470, 5.2.
	StatusUpgradeRequired              = http.StatusUpgradeRequired              // RFC 9110, 15.5.22
	StatusPreconditionRequired         = http.StatusPreconditionRequired         // RFC 6585, 3
	StatusTooManyRequests              = http.StatusTooManyRequests              // RFC 6585, 4
	StatusRequestHeaderFieldsTooLarge  = http.StatusRequestHeaderFieldsTooLarge  // RFC 6585, 5
	StatusUnavailableForLegalReasons   = http.StatusUnavailableForLegalReasons   // RFC 7725, 3

	StatusInternalServerError           = http.StatusInternalServerError           // RFC 9110, 15.6.1
	StatusNotImplemented                = http.StatusNotImplemented                // RFC 9110, 15.6.2
	StatusBadGateway                    = http.StatusBadGateway                    // RFC 9110, 15.6.3
	StatusServiceUnavailable            = http.StatusServiceUnavailable            // RFC 9110, 15.6.4
	StatusGatewayTimeout                = http.StatusGatewayTimeout                // RFC 9110, 15.6.5
	StatusHTTPVersionNotSupported       = http.StatusHTTPVersionNotSupported       // RFC 9110, 15.6.6
	StatusVariantAlsoNegotiates         = http.StatusVariantAlsoNegotiates         // RFC 2295, 8.1
	StatusInsufficientStorage           = http.StatusInsufficientStorage           // RFC 4918, 11.5
	StatusLoopDetected                  = http.StatusLoopDetected                  // RFC 5842, 7.2
	StatusNotExtended                   = http.StatusNotExtended                   // RFC 2774, 7
	StatusNetworkAuthenticationRequired = http.StatusNetworkAuthenticationRequired // RFC 6585, 6
)

Variables

This section is empty.

Functions

func StatusText

func StatusText(code int) string

Types

type Context

type Context interface {
	fiber.Ctx
	// CTX 获取fiber.Ctx
	CTX() fiber.Ctx
	// Proxy 获取代理API
	Proxy() *Proxy
	// Failure 失败响应
	Failure(rst any) error
	// Success 成功响应
	Success(data ...any) error
	// StdRequest 获取标准请求(net/http)
	StdRequest() *http.Request
}

type CorsOptions

type CorsOptions struct {
	Enable              bool     `json:"enable"`              // 是否启用
	AllowOrigins        []string `json:"allowOrigins"`        // 允许跨域的请求源。默认为[],即为允许所有请求源
	AllowMethods        []string `json:"allowMethods"`        // 允许跨域的请求方法。默认为["GET", "POST", "HEAD", "PUT", "DELETE", "PATCH"]
	AllowHeaders        []string `json:"allowHeaders"`        // 允许跨域的请求头部。默认为[],即为允许所有请求头部
	AllowCredentials    bool     `json:"allowCredentials"`    // 当允许所有源时,根据CORS规范不允许携带凭据。默认为false
	ExposeHeaders       []string `json:"exposeHeaders"`       // 允许暴露给客户端的头部。默认为[],即为允许暴露所有头部
	MaxAge              int      `json:"maxAge"`              // 浏览器缓存预检请求结果的时间。默认为0
	AllowPrivateNetwork bool     `json:"allowPrivateNetwork"` // 是否允许来自私有网络的请求。设置为true时,响应头Access-Control-Allow-Private-Network会被设置为true。默认为false
}

type Handler

type Handler = func(ctx Context) error

type Option

type Option func(o *options)

func WithAddr

func WithAddr(addr string) Option

WithAddr 设置监听地址

func WithCorsOptions

func WithCorsOptions(corsOpts CorsOptions) Option

WithCorsOptions 设置跨域配置

func WithCredentials

func WithCredentials(certFile, keyFile string) Option

WithCredentials 设置证书和秘钥

func WithMiddlewares

func WithMiddlewares(middlewares ...any) Option

WithMiddlewares 设置中间件

func WithName

func WithName(name string) Option

WithName 设置实例名称

func WithRegistry

func WithRegistry(r gregistry.Registry) Option

WithRegistry 设置服务注册器

func WithSwagOptions

func WithSwagOptions(swagOpts SwagOptions) Option

WithSwagOptions 设置swagger配置

func WithTransporter

func WithTransporter(transporter gtransport.Transporter) Option

WithTransporter 设置消息传输器

type Proxy

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

func (*Proxy) NewMeshClient

func (p *Proxy) NewMeshClient(target string) (gtransport.Client, error)

NewMeshClient 新建微服务客户端 target参数可分为三种模式: 服务直连模式: direct://127.0.0.1:8011 服务直连模式: direct://711baf8d-8a06-11ef-b7df-f4f19e1f0070 服务发现模式: discovery://service_name

func (*Proxy) Router

func (p *Proxy) Router() Router

Router 获取路由器

type Resp

type Resp struct {
	Code    int    `json:"code"`           // 响应码
	Message string `json:"message"`        // 响应消息
	Data    any    `json:"data,omitempty"` // 响应数据
}

type Router

type Router interface {
	// Get 添加GET请求处理器
	Get(path string, handler any, middlewares ...any) Router
	// Post 添加POST请求处理器
	Post(path string, handler any, middlewares ...any) Router
	// Head 添加HEAD请求处理器
	Head(path string, handler any, middlewares ...any) Router
	// Put 添加PUT请求处理器
	Put(path string, handler any, middlewares ...any) Router
	// Delete 添加DELETE请求处理器
	Delete(path string, handler any, middlewares ...any) Router
	// Connect 添加CONNECT请求处理器
	Connect(path string, handler any, middlewares ...any) Router
	// Options 添加OPTIONS请求处理器
	Options(path string, handler any, middlewares ...any) Router
	// Trace 添加TRACE请求处理器
	Trace(path string, handler any, middlewares ...any) Router
	// Patch 添加PATCH请求处理器
	Patch(path string, handler any, middlewares ...any) Router
	// Add 添加路由处理器
	Add(methods []string, path string, handler any, middlewares ...any) Router
	// Group 路由组
	Group(prefix string, handlers ...any) Router
	// AddHandlers 批量添加
	AddHandlers(mng ghandler.Manager, middlewares ...any) Router
}

type Server

type Server struct {
	gmodules.Base
	// contains filtered or unexported fields
}

func NewServer

func NewServer(opts ...Option) *Server

func (*Server) Init

func (s *Server) Init()

Init 初始化组件

func (*Server) Name

func (s *Server) Name() string

Name 组件名称

func (*Server) Proxy

func (s *Server) Proxy() *Proxy

Proxy 获取HTTP代理API

func (*Server) Start

func (s *Server) Start()

Start 启动组件

type SwagOptions

type SwagOptions struct {
	Enable   bool   `json:"enable"`   // 是否启用
	Title    string `json:"title"`    // 文档标题
	FilePath string `json:"filePath"` // 文档路径
	BasePath string `json:"basePath"` // 访问路径
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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