api

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2020 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 {
	Request() Request
	Response() Response
	Session() Session
	Tx() *db.Tx
}

Context ...

type Header http.Header

Header copy from net/http

func (Header) Add

func (h Header) Add(key, value string)

Add ...

func (Header) Clone

func (h Header) Clone() Header

Clone ...

func (Header) Get

func (h Header) Get(key string) string

Get ...

func (Header) Set

func (h Header) Set(key, value string)

Set ...

type Middleware

type Middleware func(ctx RequestCtx) error

Middleware ..

type Request

type Request interface {
	Header() Header
	URL() uri.URL
	JSONBody() json.Object
}

Request ...

type RequestCtx

type RequestCtx interface {
	Header() Header
	Body() []byte
	URL() url.URL
	Session() Session
	Tx() *db.Tx
}

RequestCtx ..

type Response

type Response interface {
	Header() Header
	Status() int
	Body() []byte
	Error() error
}

Response ...

func ResponseError added in v0.4.0

func ResponseError(status int, err error) (Response, error)

ResponseError used for generate response from error

type Route

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

Route ...

func NewFuncRoute added in v0.4.0

func NewFuncRoute(f func(ctx Context) (interface{}, error)) *Route

NewFuncRoute create POST route with single func action

func NewRoute added in v0.3.2

func NewRoute() *Route

NewRoute create route

func (*Route) AddFuncAction

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

AddFuncAction ...

func (*Route) AddQueryAction

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

AddQueryAction ...

func (*Route) SetSecure

func (r *Route) SetSecure(secure bool)

SetSecure ...

type Server

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

Server ...

func New added in v0.3.1

func New() *Server

New ...

func (*Server) AddAuthMiddleware

func (s *Server) AddAuthMiddleware(m Middleware)

AddAuthMiddleware ..

func (*Server) AddFuncRoute added in v0.3.2

func (s *Server) AddFuncRoute(f func(ctx Context) (interface{}, error), secure bool) (*Route, error)

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

func (*Server) AddMiddleware

func (s *Server) AddMiddleware(m Middleware)

AddMiddleware ..

func (*Server) AddQueryRoute added in v0.3.2

func (s *Server) AddQueryRoute(path, query, params string, secure bool) (*Route, error)

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

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.

func (*Server) GetRoute

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

GetRoute ...

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(host string, port int, username, password, name string) error

OpenDatabase call SetDatabase and Connect

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) SetDatabase

func (s *Server) SetDatabase(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(v ...interface{}), warn func(v ...interface{}), err func(v ...interface{}))

SetLogger ...

func (*Server) SetProduction

func (s *Server) SetProduction()

SetProduction ...

func (*Server) SetRoute

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

SetRoute ...

type Session

type Session interface {
	Put(key string, value interface{})
	Get(key string) interface{}
	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