apims

package module
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2020 License: MIT Imports: 15 Imported by: 0

README

apims

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

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

ActionFunc ...

type Context added in v0.2.1

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

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

func (r *Route) SetSecure(secure bool)

SetSecure ...

type Server

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

Server ...

func NewServer

func NewServer() *Server

NewServer ...

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

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

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

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

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

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

Session ...

Jump to

Keyboard shortcuts

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