Documentation
¶
Index ¶
- type AccessKeyType
- type AccessToken
- type CORSMiddleware
- type ContextKey
- type Gateway
- func (g *Gateway) GET(handler Handler, preprocessors ...Processor)
- func (g *Gateway) Handle(method string, handler Handler, preprocessors ...Processor)
- func (g *Gateway) POST(handler Handler, preprocessors ...Processor)
- func (g *Gateway) PUT(handler Handler, preprocessors ...Processor)
- func (g *Gateway) ServeHTTP(w http.ResponseWriter, req *http.Request)
- type Handler
- type HandlerFunc
- type HandlerInjector
- type LoggingMiddleware
- type Payload
- type PreprocessorRegistry
- type Processor
- type Response
- type Router
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccessKeyType ¶
type AccessKeyType int
AccessKeyType is the type of the access key specified in client request
const ( // NoAccessKey denotes that an access key is not specified NoAccessKey AccessKeyType = 0 + iota // ClientAccessKey denotes that a client access key is specified ClientAccessKey // MasterAccessKey denotes that a master aclieneccess key is specified MasterAccessKey )
func (AccessKeyType) String ¶
func (i AccessKeyType) String() string
type AccessToken ¶
type AccessToken interface {
// IssuedAt returns the time when the access token is issued. If the
// information is not available, the IsZero method of the
// returned time is true.
IssuedAt() time.Time
}
AccessToken is an interface to access information about the Access Token in the payload.
type CORSMiddleware ¶
func (*CORSMiddleware) ServeHTTP ¶
func (cors *CORSMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request)
type ContextKey ¶ added in v0.18.0
type ContextKey string
var UserIDContextKey ContextKey = "UserID"
type Gateway ¶
Gateway is a man in the middle to inject dependency It currently bind to HTTP method, it disregard path.
func (*Gateway) Handle ¶
Handle registers a handler matched by a request's method and URL's path. Pattern is a regexp that defines a matched URL.
type Handler ¶
Handler specifies the interface of a request handler
func NewFuncHandler ¶
func NewFuncHandler(f HandlerFunc) Handler
NewFuncHandler is intend for using in test, not actual code.
type HandlerFunc ¶
HandlerFunc specifies the function signature of a request handler function
type HandlerInjector ¶
type HandlerInjector struct {
ServiceGraph *inject.Graph
PreprocessorMap *PreprocessorRegistry
}
HandlerInjector is standard way to inject Services and Preprocessors specified by the Handler struct.
func (*HandlerInjector) Inject ¶
func (i *HandlerInjector) Inject(h Handler) Handler
func (*HandlerInjector) InjectProcessors ¶
func (i *HandlerInjector) InjectProcessors(h Handler) Handler
func (*HandlerInjector) InjectServices ¶
func (i *HandlerInjector) InjectServices(h Handler) Handler
type LoggingMiddleware ¶
func (*LoggingMiddleware) ServeHTTP ¶
func (l *LoggingMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request)
type Payload ¶
type Payload struct {
// the raw http.Request of this payload
// Think twice before accessing it
Req *http.Request
// URL parameters
Params []string
// Map of params such as Auth, TimeSteam, version
Meta map[string]interface{}
// Map of action payload
Data map[string]interface{}
Context context.Context
AppName string
UserInfoID string
UserInfo *skydb.UserInfo
AccessKey AccessKeyType
// AccessToken stores access token for this payload.
//
// The field is injected by preprocessor. The field
// is nil if the AccessToken does not exist or is not valid.
AccessToken AccessToken
DBConn skydb.Conn
Database skydb.Database
}
Payload is for passing payload to the actual handler
func (*Payload) AccessTokenString ¶
AccessTokenString return the user input string TODO: accept all header, json payload, query string(in order)
func (*Payload) HasMasterKey ¶
HasMasterKey returns whether the payload has master access key
func (*Payload) RouteAction ¶
RouteAction must exist for every request
type PreprocessorRegistry ¶
PreprocessorRegistry is holding all preprocessors and their mapping with a string name.
func (PreprocessorRegistry) GetByNames ¶
func (r PreprocessorRegistry) GetByNames(names ...string) []Processor
GetByNames returns a list of registered preprocessors by preprocessor names.
type Response ¶
type Response struct {
Meta map[string][]string `json:"-"`
Info interface{} `json:"info,omitempty"`
Result interface{} `json:"result,omitempty"`
Err skyerr.Error `json:"error,omitempty"`
RequestID string `json:"request_id,omitempty"`
DatabaseID string `json:"database_id,omitempty"`
// contains filtered or unexported fields
}
Response is interface for handler to write response to router
func (*Response) Header ¶
Header returns the header map being written before return a response. Mutating the map after calling WriteEntity has no effects.
func (*Response) WriteEntity ¶
WriteEntity writes a value as response to a request. Currently it only writes JSON response.
func (*Response) WriteHeader ¶
WriteHeader sends an HTTP response header with status code.