fastresponse

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

README

Frame 1
一个基于“gnet”的小巧、快速、高性能的Web框架。
A small, fast, high-performance web framework based on gnet.

English | 简体中文 | 繁體中文

How to Use it

go get github.com/fast-response/fast-response

Functions

  • JSON operate
  • Chunked
  • From-data
  • Cookie operate

Protocol

  • HTTP/1
  • HTTP/1.1
  • HTTP/2
  • HTTP/3
  • WS
  • SSL/TLS(Need to wait for gnet implementation)

The person using it

玄云海长Logo

Safety

Security Status

Thanks

gnet

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Code = map[int]string{
	100: "Continue",
	101: "Switching Protocols",
	200: "OK",
	201: "Created",
	202: "Accepted",
	203: "Non-Authoritative Information",
	204: "No Content",
	205: "Reset Content",
	206: "Partial Content",
	300: "Multiple Choices",
	301: "Moved Permanently",
	302: "Found",
	303: "See Other",
	304: "Not Modified",
	305: "Use Proxy",
	306: "Unused",
	307: "Temporary Redirect",
	400: "Bad Request",
	401: "Unauthorized",
	402: "Payment Required",
	403: "Forbidden",
	404: "Not Found",
	405: "Method Not Allowed",
	406: "Not Acceptable",
	407: "Proxy Authentication Required",
	408: "Request Time-out",
	409: "Conflict",
	410: "Gone",
	411: "Length Required",
	412: "Precondition Failed",
	413: "Request Entity Too Large",
	414: "Request-URI Too Large",
	415: "Unsupported Media Type",
	416: "Requested range not satisfiable",
	417: "Expectation Failed",
	500: "Internal Server Error",
	501: "Not Implemented",
	502: "Bad Gateway",
	503: "Service Unavailable",
	504: "Gateway Time-out",
	505: "HTTP Version not supported",
}

Functions

func AddFormData

func AddFormData(app *App, Remote string, buf []byte, c gnet.Conn) gnet.Action

func AddToConnectionQueue

func AddToConnectionQueue(app *App, Remote string, BoundaryName string, req *Request, res *Response, function func(*Request, *Response), c gnet.Conn)

func Byte2String

func Byte2String(b byte) string

func Bytes2String

func Bytes2String(b []byte) string

func BytesCombine2

func BytesCombine2(pBytes ...[]byte) []byte

func ContainsInSlice

func ContainsInSlice(items []string, item string) bool

func GenerateCookies

func GenerateCookies(res *Response)

func GetErrPage

func GetErrPage(req *Request, res *Response, err string, errCode int)

func ParseCookies

func ParseCookies(req *Request)

func Run

func Run(app *App) error

func SetErrPage

func SetErrPage(errCode int, function func(*Request, *Response, string, int))

func String2Slice

func String2Slice(s string) (b []byte)

func Time2HttpDate

func Time2HttpDate() string

Types

type App

type App struct {
	// Route, Reference Router Type
	Router *Router

	// Configuration Data, Reference Config Type
	Config *Config

	// ConnectionQueue
	ConnectionQueue map[string]*Connection

	// ConnectionQueue Lock
	ConnectionQueueLock sync.RWMutex
}

func NewApp

func NewApp(c *Config) *App

type Config

type Config struct {
	// Listening port, Default is 8080
	Port int

	// The host address being monitored will be monitored by default, including IPv6
	Host string

	// The log level is currently invalid, but it is currently under development
	LogLevel string

	// Multicore switch, which can increase speed for multicore devices
	Multicore bool

	// HTTP Proxy Mode
	ProxyMode bool
}

type Connection

type Connection struct {
	BoundaryName     string
	LastFormDataName string
	FormData         map[string]*FormData

	Lock *sync.Mutex
	// contains filtered or unexported fields
}
type Cookie struct {
	// Represents the value of the cookie.
	Value string

	// Represents the name of the cookie.
	Name string

	// Represents the path of the cookie.
	Path string

	// Represents the domain of the cookie.
	Domain string

	// A boolean value indicating whether the cookie can only be accessed via HTTP and cannot be accessed by client-side scripts (e.g., JavaScript).
	HttpOnly bool

	// A boolean value indicating whether the cookie can only be accessed via HTTPS and cannot be accessed by HTTP.
	Secure bool

	// A boolean value indicating whether the maximum age functionality is enabled for the cookie. If enabled, it is true; otherwise, it is false.
	MaxAgeEnable bool
	// contains filtered or unexported fields
}

func (*Cookie) SetExpires

func (cookie *Cookie) SetExpires(t int64)

func (*Cookie) SetMaxAge

func (cookie *Cookie) SetMaxAge(t int64)

type FormData

type FormData struct {
	Type    string
	Value   *bytes.Buffer
	Name    string
	Headers map[string][]string
}

type Request

type Request struct {
	// URI of the request
	Uri *url.URL

	// Headers contains the headers
	Headers map[string][]string

	// Body contains the body of the request
	Body []byte

	// Path contains the parsed path of the request
	Path string

	// Method contains the HTTP method of the request
	Method string

	// Raw contains the raw bytes of the request
	Raw []byte

	// Version of the HTTP protocol used in the request
	Version string

	// Address of the remote peer of the request
	Addr string

	// Params contains the parsed parameters of the request
	Param map[string]string

	// Cookies contains the parsed cookies of the request
	Cookies map[string]*Cookie

	FormData map[string]*FormData
}

func NewRequest

func NewRequest(ReqText []byte, app *App) (*Request, string)

func (*Request) AddToConnectionQueue

func (req *Request) AddToConnectionQueue(app *App, Remote string, res *Response, function func(*Request, *Response), c gnet.Conn) bool

func (*Request) GetHeader

func (req *Request) GetHeader(name string) []string

func (*Request) Json

func (req *Request) Json(obj any) error

func (*Request) Text

func (req *Request) Text() string

type Response

type Response struct {
	// HTTP response code
	Code string

	// Cookies contains the parsed cookies of the response
	Cookies map[string]*Cookie

	// Request is the *Request that generated this Response.
	// It can be used for getting request specific values.
	Req *Request

	// Chunked controls whether chunked transfer encoding should be applied.
	Chunked bool

	// Connection of the response. This is the gnet.Conn object of the connection from the client.
	Conn gnet.Conn
	// contains filtered or unexported fields
}

func NewResponse

func NewResponse(req *Request, Conn gnet.Conn) *Response

func (*Response) AddCookie

func (res *Response) AddCookie(cookie *Cookie)

func (*Response) GetBody

func (res *Response) GetBody() []byte

func (*Response) GetHeader

func (res *Response) GetHeader(name string) []string

func (*Response) GetHeaders

func (res *Response) GetHeaders() map[string][]string

func (*Response) GetRaw

func (res *Response) GetRaw() []byte

func (*Response) PushBody

func (res *Response) PushBody(content []byte)

func (*Response) PushBodyEnd

func (res *Response) PushBodyEnd()

func (*Response) RemoveHeader

func (res *Response) RemoveHeader(name string, content string) string

func (*Response) SetBody

func (res *Response) SetBody(body []byte)

func (*Response) SetCode

func (res *Response) SetCode(code int)

func (*Response) SetContentType

func (res *Response) SetContentType(contentType string)

func (*Response) SetHeader

func (res *Response) SetHeader(name string, content string) string

func (*Response) SetJson

func (res *Response) SetJson(data any) error

func (*Response) SetText

func (res *Response) SetText(text string)

func (*Response) String

func (res *Response) String() string

type Router

type Router struct {
	Routes map[string]func(*Request, *Response)
}

func (*Router) Add

func (r *Router) Add(rule string, function func(*Request, *Response))

func (*Router) MatchRoute

func (r *Router) MatchRoute(uri string, rule string) (bool, map[string]string)

func (*Router) MatchRoutes

func (r *Router) MatchRoutes(app *App, c gnet.Conn) gnet.Action

func (*Router) To

func (r *Router) To(uri string) func(*Request, *Response)

Jump to

Keyboard shortcuts

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