zeus

package module
v0.0.0-...-9dc91f1 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

README

Zeus

A Go Web Framework as fast as thunder

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	Action  string
	Request *http.Request
	Writer  ResponseWriter
	Buf     []byte

	Zeus *Zeus
	// contains filtered or unexported fields
}

func (*Context) Bind

func (c *Context) Bind(v any) error

Bind is used to bind the request to v, set the default and validate the data.

func (*Context) ClientIP

func (c *Context) ClientIP() string

func (*Context) ContentLength

func (c *Context) ContentLength() int64

ContentLength return the length of the request body.

func (*Context) ContentType

func (c *Context) ContentType() (ct string)

ContentType returns the Content-Type of the request without the charset.

func (*Context) GetQuery

func (c *Context) GetQuery(key string) string

GetQuery is equal to c.Query().Get(key).

func (*Context) GetRequestHeader

func (c *Context) GetRequestHeader(key string) string

GetRequestHeader is equal to c.Request().Header.Get(key).

func (*Context) IsWebSocket

func (c *Context) IsWebSocket() bool

IsWebSocket reports whether HTTP connection is WebSocket or not.

func (*Context) JSON

func (c *Context) JSON(code int, obj any) error

JSON serializes the given struct as JSON into the response body.

func (*Context) JSONP

func (c *Context) JSONP(code int, obj any) error

JSONP serializes the given struct as JSON into the response body. It adds padding to response body to request data from a server residing in a different domain than the client. It also sets the Content-Type as "application/javascript".

func (*Context) Query

func (c *Context) Query() url.Values

Query parses and returns the query of the request.

func (*Context) QueryMap

func (c *Context) QueryMap() map[string]any

QueryMap parses and returns the query of the request.

func (*Context) Render

func (c *Context) Render(code int, r render.Render) error

Render writes the response headers and calls render.Render to render data.

func (*Context) ShouldBindJSON

func (c *Context) ShouldBindJSON(obj any) error

ShouldBindJSON is a shortcut for c.ShouldBindWith(obj, binder.Json).

func (*Context) ShouldBindQuery

func (c *Context) ShouldBindQuery(obj any) error

ShouldBindQuery is a shortcut for c.ShouldBindWith(obj, binder.Query).

func (*Context) ShouldBindWith

func (c *Context) ShouldBindWith(obj any, b binder.Binder) error

ShouldBindWith binds the passed struct pointer using the specified binder engine. See the binder package.

func (*Context) String

func (c *Context) String(code int, format string, values ...any) error

String sends the string text to the client with status code.

type HandlerFunc

type HandlerFunc func(*Context) error

HandlerFunc is the handler of the service.

type MiddlewareFunc

type MiddlewareFunc func(HandlerFunc) HandlerFunc

MiddlewareFunc is the handler middleware.

type ResponseWriter

type ResponseWriter interface {
	http.ResponseWriter

	Status() int

	Size() int

	WriteString(string) (int, error)

	Written() bool

	WriteHeaderNow()
}

ResponseWriter ...

type Zeus

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

func New

func New() *Zeus

func (*Zeus) AcquireContext

func (z *Zeus) AcquireContext(r *http.Request, w http.ResponseWriter) *Context

AcquireContext acquires a Context from the pool.

func (*Zeus) ErrHandler

func (z *Zeus) ErrHandler(c *Context, err error)

func (*Zeus) Handler

func (z *Zeus) Handler(name string) (HandlerFunc, bool)

func (*Zeus) Register

func (z *Zeus) Register(action string, handler HandlerFunc, mws ...MiddlewareFunc)

Register registers a service with the name and the handler.

func (*Zeus) ReleaseContext

func (z *Zeus) ReleaseContext(c *Context)

ReleaseContext releases a Context into the pool.

func (*Zeus) Run

func (z *Zeus) Run(addr ...string) (err error)

func (*Zeus) ServeHTTP

func (z *Zeus) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Zeus) Use

func (z *Zeus) Use(mws ...MiddlewareFunc)

Use registers the global middlewares that apply to all the services.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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