include

package
v0.0.0-...-99127cc Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	/* request methods */
	ChHttpGet    int = 0x01
	ChHttpPut    int = 0x02
	ChHttpPost   int = 0x03
	ChHttpHead   int = 0x04
	ChHttpOption int = 0x05

	/* ASCII */
	ChStrSpace = 0x20
	ChStrLf    = 0x0a
	ChStrCr    = 0x0d
	ChStrQry   = 0x3f
	ChStrColon = 0x3a
)

Variables

View Source
var (
	/* Http versions */
	HttpVerUn = []byte{0x75, 0x6e, 0x6b, 0x6e, 0x6f, 0x77, 0x6e}       //unknown
	HttpVer10 = []byte{0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x30} // HTTP/1.0
	HttpVer11 = []byte{0x48, 0x54, 0x54, 0x50, 0x2f, 0x31, 0x2e, 0x31} // HTTP/1.1
	HttpVer20 = []byte{0x48, 0x54, 0x54, 0x50, 0x2f, 0x32, 0x2e, 0x30} // HTTP/2.0

	/* http connection */
	HttpClose = []byte{0x63, 0x6c, 0x6f, 0x73, 0x65} // close

	/* Http Status Code */
	St200 = []byte(" 200 OK")
	St403 = []byte(" 403 Forbidden")
	St404 = []byte(" 404 Not Found")
	St405 = []byte(" 405 Method Not Allowed")
)

Functions

This section is empty.

Types

type ChRequest

type ChRequest struct {
	Method   int
	Resource []byte
	Version  []byte
	Args     []byte
	ArgsMap  map[string]string
	Header   map[string][]byte
	Body     []byte
}

func NewRequest

func NewRequest() *ChRequest

NewRequest Request struct build func

func (*ChRequest) GetData

func (cr *ChRequest) GetData() string

GetData get client request payload

func (*ChRequest) GetHeader

func (cr *ChRequest) GetHeader(key string) string

GetHeader using the keyword fetch header from headers

func (*ChRequest) GetHttpVersion

func (cr *ChRequest) GetHttpVersion() string

GetHttpVersion get the client http request version

func (*ChRequest) GetJson

func (cr *ChRequest) GetJson(path string) (res gjson.Result)

GetJson try to fetch json data from request body

func (*ChRequest) GetMethod

func (cr *ChRequest) GetMethod() string

GetMethod get the client http request method

func (*ChRequest) GetQueryArgument

func (cr *ChRequest) GetQueryArgument(key string) string

GetQueryArgument get the client http request argument

type ChResponse

type ChResponse struct {
	Code    []byte
	Headers map[string]string
	Body    []byte
	Ctl     map[string]string
}

func ChForbidden

func ChForbidden() *ChResponse

ChForbidden return 403 html content

func ChMethodNotAllowed

func ChMethodNotAllowed() *ChResponse

ChMethodNotAllowed return 405 html content

func ChNotFound

func ChNotFound() *ChResponse

ChNotFound return 404 html content

func NewChResponse

func NewChResponse() *ChResponse

func (*ChResponse) Jsonify

func (cr *ChResponse) Jsonify(v map[string]interface{}) (ok bool)

func (*ChResponse) SetReturnJson

func (cr *ChResponse) SetReturnJson()

type ChRouters

type ChRouters struct {
	Routers map[string]struct {
		Method  []int
		Handler func(req *ChRequest, res *ChResponse) *ChResponse
	}
}

func (*ChRouters) Add

func (cr *ChRouters) Add(router string, methods []int, handler func(req *ChRequest, res *ChResponse) *ChResponse)

Add add a router into chainx routers map

type JSON

type JSON map[string]interface{}

Jump to

Keyboard shortcuts

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