api

package module
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2021 License: MIT Imports: 16 Imported by: 8

README

api-server

Documentation

Index

Constants

View Source
const (
	//MethodGet GET
	MethodGet string = fasthttp.MethodGet
	//MethodPost POST
	MethodPost string = fasthttp.MethodPost

	//StatusBadRequest ...
	StatusBadRequest = fasthttp.StatusBadRequest
	//StatusUnauthorized ...
	StatusUnauthorized = fasthttp.StatusUnauthorized
	//StatusNotFound ...
	StatusForbidden = fasthttp.StatusForbidden
	//StatusNotFound ...
	StatusNotFound = fasthttp.StatusNotFound
	//StatusOK ...
	StatusOK = 200

	//StatusInternalServerError ...
	StatusInternalServerError = fasthttp.StatusInternalServerError
	StatusServiceUnavailable  = fasthttp.StatusServiceUnavailable

	//StatusBadGateway ...
	StatusBadGateway = 502
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action interface {
	// contains filtered or unexported methods
}

Action ...

type Context

type Context interface {
	URL() *url.URL
	Method() string
	ContentType() string
	RemoteIP() string
	Write(value interface{}) error

	//WriteBody write to body and ignoring the next action
	WriteBody(contentType string, body []byte) error
	//Status stop execution and return status and message
	Status(status int, msg string) error
	//Error stop execution, rollback database transaction, and return status and message
	Error(status int, msg string) error

	//StatusBadRequest 400
	StatusBadRequest(msg string) error
	//StatusUnauthorized 401
	StatusUnauthorized(msg string) error
	//StatusUnauthorized 403
	StatusForbidden(msg string) error
	//StatusNotFound 404
	StatusNotFound(msg string) error
	StatusServiceUnavailable(msg string) error
	StatusInternalServerError(msg string) error

	Redirect(url string) error

	Request() Request
	Response() Response

	Tx() (*db.Tx, error)
	Session() Session
	SetValue(name string, value interface{})
	GetValue(name string) interface{}
}

Context ..

type Group added in v0.6.0

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

Group ..

func (*Group) AddMiddleware added in v0.6.0

func (g *Group) AddMiddleware(f func(Context) error) Middleware

AddMiddleware ..

func (*Group) Get added in v0.6.1

func (g *Group) Get(path string) *Route

func (*Group) GetAction added in v0.7.0

func (g *Group) GetAction(f func(Context) error) *Route

func (*Group) GetSecureAction added in v0.7.0

func (g *Group) GetSecureAction(f func(Context) error) *Route

func (*Group) Post added in v0.6.0

func (g *Group) Post(path string) *Route

func (*Group) PostAction added in v0.7.0

func (g *Group) PostAction(f func(Context) error) *Route

func (*Group) PostSecureAction added in v0.7.0

func (g *Group) PostSecureAction(f func(Context) error) *Route

type Middleware

type Middleware interface {
	//ForGroup set name for this middleware, this middleware only used by route that requiring the same name
	ForGroup(string) Middleware
	Secure() Middleware
}

Middleware ..

type Render added in v0.7.1

type Render func(Context) bool

type Request

type Request interface {
	Header() *RequestHeader
	Method() string
	URL() *url.URL
	JSON() json.Object
	Body() []byte
}

Request ..

type RequestHeader added in v0.5.0

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

RequestHeader ...

func (*RequestHeader) Bytes added in v0.6.0

func (r *RequestHeader) Bytes() []byte

func (*RequestHeader) Get added in v0.5.0

func (r *RequestHeader) Get(key string) string

Get ..

type Response

type Response interface {
	ContentType() string
	SetContentType(contentType string)
	StatusCode() int
	StatusMessage() string
	SetStatusCode(statusCode int)
	Header() *ResponseHeader
	Put(key string, value interface{})
	Data() json.Object
	Body() []byte
	SetBody(body []byte)
}

type ResponseHeader added in v0.5.1

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

ResponseHeader ...

func (*ResponseHeader) Add added in v0.5.1

func (r *ResponseHeader) Add(key, value string)

Add ..

func (*ResponseHeader) Get added in v0.7.0

func (r *ResponseHeader) Get(key string) string

Get ..

func (*ResponseHeader) Set added in v0.5.1

func (r *ResponseHeader) Set(key, value string)

Set ..

func (*ResponseHeader) SetCookie added in v0.7.0

func (r *ResponseHeader) SetCookie(key, value string, expire int)

type Route

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

Route ...

func (*Route) AddAction added in v0.7.0

func (r *Route) AddAction(property string, f func(Context) error) *Route

AddAction ...

func (*Route) AddQueryAction

func (r *Route) AddQueryAction(property, query, params string) *Route

AddQueryAction ...

func (*Route) Secure added in v0.6.0

func (r *Route) Secure() *Route

Secure ...

func (*Route) UseGroup added in v0.6.0

func (r *Route) UseGroup(name string) *Route

UseGroup only use middleware that have the same name or no name

type Server

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

Server ...

func New added in v0.3.1

func New() *Server

New ...

func (*Server) AddMiddleware

func (s *Server) AddMiddleware(f func(Context) error) Middleware

AddMiddleware ..

func (*Server) Connect

func (s *Server) Connect() error

Connect ...

func (*Server) Database

func (s *Server) Database() *db.Connection

Database ...

func (*Server) FileRoute added in v0.4.0

func (s *Server) FileRoute(path, dest, redirectTo string) error

FileRoute serve static file. Path parameter to determine url to be processed. Dest parameter will find directory of the file reside. RedirectTo parameter to redirect non existing file, this param can be used for SPA (ex. index.html).

func (*Server) FileRouteRemove added in v0.4.1

func (s *Server) FileRouteRemove(path string) error

FileRouteRemove ...

func (*Server) Get added in v0.6.1

func (s *Server) Get(path string) *Route

func (*Server) Group added in v0.6.0

func (s *Server) Group(name string) *Group

Group ..

func (*Server) NormalizeFunc added in v0.3.2

func (s *Server) NormalizeFunc(n bool)

NormalizeFunc if yes from this and beyond all Func added will renamed to lowercase, separated with underscore. Ex: HelloWorld registered as hello_world

func (*Server) OpenDatabase

func (s *Server) OpenDatabase(driver, host string, port int, username, password, name string) error

OpenDatabase ..

func (*Server) Post added in v0.6.0

func (s *Server) Post(path string) *Route

func (*Server) PostAction added in v0.7.0

func (s *Server) PostAction(f func(Context) error) *Route

func (*Server) PostSecureAction added in v0.7.0

func (s *Server) PostSecureAction(f func(Context) error) *Route

func (*Server) Proxy added in v0.4.0

func (s *Server) Proxy(path, dest string) error

Proxy ...

func (*Server) Serve

func (s *Server) Serve(port int) error

Serve ..

func (*Server) SetLogger

func (s *Server) SetLogger(debug func(...interface{}), info func(...interface{}), warn func(...interface{}), err func(...interface{}))

SetLogger ...

func (*Server) SetRender added in v0.7.1

func (s *Server) SetRender(r Render)

func (*Server) Shutdown added in v0.5.1

func (s *Server) Shutdown() error

Shutdown ..

type Session

type Session interface {
	Put(key string, value interface{})
	Get(key string) interface{}
	Remove(key string)
	GetInt(key string) int
	GetString(key string) string
}

Session ...

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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