api

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2020 License: MIT Imports: 17 Imported by: 8

README

api-server

Documentation

Index

Constants

View Source
const (
	//MethodGet GET
	MethodGet = `GET`
	//MethodPost POST
	MethodPost = `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 (*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) AddDataRoute

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

AddDataRoute add query with action result to property named "data"

func (*Server) AddFunc

func (s *Server) AddFunc(f ActionFunc) (*Route, error)

AddFunc add insecure route with single func action, insecure means this route will not validated by auth middlewares.

func (*Server) AddMiddleware

func (s *Server) AddMiddleware(m Middleware)

AddMiddleware ..

func (*Server) AddPostRoute

func (s *Server) AddPostRoute(path string) (*Route, error)

AddPostRoute ...

func (*Server) AddRoute

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

AddRoute ...

func (*Server) AddSecureFunc

func (s *Server) AddSecureFunc(f ActionFunc) (*Route, error)

AddSecureFunc add secure route with single func action, secure means 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) OpenDatabase

func (s *Server) OpenDatabase(host string, port uint16, 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 uint16, 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) error

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