coreapi

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2018 License: BSD-3-Clause Imports: 10 Imported by: 16

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	InternalServerErr = APIError{
		Code:       10000,
		StatusCode: http.StatusInternalServerError,
	}
	EntityNotFoundErr = APIError{
		StatusCode: http.StatusNotFound,
	}
)

Functions

func RegisterCache

func RegisterCache(key string, makeF func() (RawCache, error))

func RegisterLogger

func RegisterLogger(key string, makeF func() (Logger, error))

Types

type APIError

type APIError struct {
	Code       int    `json:"code"`
	Message    string `json:"-"`
	StatusCode int    `json:"-"`
}

func (APIError) Error

func (err APIError) Error() string

type APIHandler

type APIHandler func(req *http.Request) (interface{}, error)

API declaration

type APIMiddleware

type APIMiddleware func(next APIHandler) APIHandler

type Cache

type Cache interface {
	Get(key string, val interface{}) bool
	Set(key string, val interface{})
	Del(key string)
}

type Common

type Common struct {
	Logger Logger
	Cache  Cache
}

type Core

type Core struct {
	Common Common
	HTTP   HTTP
}

func Init

func Init() Core

type HTTP

type HTTP struct {
	WrapAPIHandler func(fun APIHandler) http.Handler
	Router         *pat.PatternServeMux
}

type Logger

type Logger interface {
	Info(format string, args ...interface{})
	Warn(format string, args ...interface{})
	Err(format string, args ...interface{})
}

type Middleware

type Middleware func(next http.Handler) http.Handler

type RawCache

type RawCache interface {
	Get(key string, val interface{}) (bool, error)
	Set(key string, val interface{}) error
	Del(key string) error
}

Jump to

Keyboard shortcuts

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