api

package module
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 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
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

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

Action ...

type ActionFunc

type ActionFunc func(ctx Context) (interface{}, error)

ActionFunc ...

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

Response ...

type Route

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

Route ...

func NewRoute added in v0.3.2

func NewRoute(method, path string) *Route

NewRoute create route

func (*Route) AddFuncAction

func (r *Route) AddFuncAction(f ActionFunc, 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 ActionFunc, 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) Execute

func (s *Server) Execute(method, url, header, body []byte) (Response, error)

Execute request and Response header and body

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) 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(route *Route)

SetRoute ...

type Session

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