api

package module
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2021 License: MIT Imports: 17 Imported by: 8

README

api-server

Documentation

Index

Constants

View Source
const (
	//MethodGet GET
	MethodGet string = `GET`
	//MethodPost POST
	MethodPost string = `POST`

	//StatusBadRequest ...
	StatusBadRequest = 400
	//StatusUnauthorized ...
	StatusUnauthorized = 401
	//StatusNotFound ...
	StatusNotFound = 404
	//StatusOK ...
	StatusOK = 200

	//StatusInternalServerError ...
	StatusInternalServerError = 500

	//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 {
	Session() Session
	Request() Request
	Response() Response
	Tx() *db.Tx
	SetValue(name string, value interface{})
	GetValue(name string) interface{}
}

Context ..

type Data added in v0.6.0

type Data struct {
	ContentType string
	Body        []byte
}

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) Func added in v0.6.0

func (g *Group) Func(f func(Context) (interface{}, error)) (*Route, error)

Func add route with single func action. When secure is true, this route will validated using auth middlewares if any.

func (*Group) FuncSecure added in v0.6.0

func (g *Group) FuncSecure(f func(Context) (interface{}, error)) (*Route, error)

FuncSecure ..

func (*Group) Get added in v0.6.1

func (g *Group) Get(path string, f func(Context) (interface{}, error)) *Route

Get ..

func (*Group) Post added in v0.6.0

func (g *Group) Post(path string, f func(Context) (interface{}, error)) *Route

Post ..

func (*Group) PostSecure added in v0.6.0

func (g *Group) PostSecure(path string, f func(Context) (interface{}, error)) *Route

PostSecure ..

func (*Group) Query added in v0.6.0

func (g *Group) Query(path, query, params string) (*Route, error)

Query add route with single query action. When secure is true, this route will validated using auth middlewares if any.

func (*Group) QuerySecure added in v0.6.0

func (g *Group) QuerySecure(path, query, params string) (*Route, error)

QuerySecure ..

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 Request

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

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 ..

func (*RequestHeader) GetOrNil added in v0.5.1

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

GetOrNil ..

type Response

type Response interface {
	Header() *ResponseHeader
	Body() []byte
	SetBody(body []byte)
	ContentType() string
	SetStatus(status int, msg string)
	SetStatusCode(status int)
	SetStatusMessage(msg string)
}

Response ..

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) Set added in v0.5.1

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

Set ..

type Route

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

Route ...

func (*Route) AddFuncAction

func (r *Route) AddFuncAction(f func(Context) (interface{}, error), property string) Action

AddFuncAction ...

func (*Route) AddQueryAction

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

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 RouteAuthenticator added in v0.5.0

type RouteAuthenticator func(ctx Context) error

RouteAuthenticator ..

type Server

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

Server ...

func New added in v0.3.1

func New() *Server

New ...

func (*Server) AddFinalHandler added in v0.5.0

func (s *Server) AddFinalHandler(f func(Context))

AddFinalHandler ..

func (*Server) AddMiddleware

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

AddMiddleware ..

func (*Server) AddRouteAuthenticator added in v0.5.0

func (s *Server) AddRouteAuthenticator(a RouteAuthenticator)

AddRouteAuthenticator ..

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) Func added in v0.6.0

func (s *Server) Func(f func(Context) (interface{}, error)) (*Route, error)

Func add route with single func action. When secure is true, this route will validated using auth middlewares if any.

func (*Server) FuncSecure added in v0.6.0

func (s *Server) FuncSecure(f func(Context) (interface{}, error)) (*Route, error)

FuncSecure ..

func (*Server) Get added in v0.6.1

func (s *Server) Get(path string, f func(Context) (interface{}, error)) *Route

Get ..

func (*Server) GetRoute

func (s *Server) GetRoute(method, path string) (*Route, error)

GetRoute ...

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 call SetDatabase and Connect

func (*Server) Post added in v0.6.0

func (s *Server) Post(path string, f func(Context) (interface{}, error)) *Route

Post ..

func (*Server) PostSecure added in v0.6.0

func (s *Server) PostSecure(path string, f func(Context) (interface{}, error)) *Route

PostSecure ..

func (*Server) Proxy added in v0.4.0

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

Proxy ...

func (*Server) Query added in v0.6.0

func (s *Server) Query(path, query, params string) (*Route, error)

Query add route with single query action. When secure is true, this route will validated using auth middlewares if any.

func (*Server) QuerySecure added in v0.6.0

func (s *Server) QuerySecure(path, query, params string) (*Route, error)

QuerySecure ..

func (*Server) Serve

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

Serve ..

func (*Server) SetDatabase

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

SetDatabase ...

func (*Server) SetDebug

func (s *Server) SetDebug()

SetDebug ...

func (*Server) SetLogger

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

SetLogger ...

func (*Server) SetProduction

func (s *Server) SetProduction()

SetProduction ...

func (*Server) SetRoute

func (s *Server) SetRoute(method, path string, route *Route)

SetRoute ...

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
helloworld command
secure command

Jump to

Keyboard shortcuts

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