Documentation ¶
Index ¶
- Constants
- Variables
- func C(f ApiCall) func(http.ResponseWriter, *http.Request)
- func DisableLog()
- func MapError(scope, msg string, err error) error
- func NewRouter() *mux.Router
- func NotFound(ctx *Context) (interface{}, int)
- func ParseErrorFromByte(b []byte, status int) error
- func ParseErrorFromStream(i io.Reader, status int) error
- func Query(ctx *Context, key string) (mode pack.FilterMode, val string, ok bool)
- func Register(model RESTful)
- func StateOptions(ctx *Context) (interface{}, int)
- func UseLogger(logger logpkg.Logger)
- type ApiCall
- type ApiErrorWrapper
- type Config
- type Context
- type Dispatcher
- type Error
- func (e *Error) Complete(code int, detail string, err error) error
- func (e *Error) CompleteApiError(code int, detail string, err error) *Error
- func (e *Error) Error() string
- func (e *Error) Marshal() []byte
- func (e *Error) MarshalIndent() []byte
- func (e *Error) SetScope(s string)
- func (e *Error) String() string
- func (e *Error) WithReason(r string) *Error
- func (e *Error) WithRequestId(i string) *Error
- func (e *Error) WithScope(s string) *Error
- type ErrorList
- type ErrorResponse
- type ErrorWrapper
- type HttpConfig
- type Options
- type ParsableRequest
- type PerformanceCounter
- type RESTful
- type Resource
- type RestServer
- type Worker
Constants ¶
View Source
const ( EC_NO_ROUTE = 1000 + iota EC_CONTENTTYPE_UNSUPPORTED EC_CONTENTTYPE_UNEXPECTED EC_MARSHAL_FAILED EC_DEMARSHAL_FAILED EC_BAD_URL_QUERY EC_PARAM_REQUIRED EC_PARAM_INVALID EC_PARAM_NOISOLANG EC_PARAM_NOISOCOUNTRY EC_PARAM_NOTEXPECTED )
10xx - HTTP errors
View Source
const ( EC_DATABASE = 1100 + iota EC_SERVER EC_RPC EC_NETWORK )
11xx - internal server error codes
View Source
const ( EC_ACCESS_HEADER_MISSING = 1200 + iota EC_ACCESS_APIKEY_MISSING EC_ACCESS_APIKEY_INVALID EC_ACCESS_APIKEY_INACTIVE EC_ACCESS_APIVERSION_INVALID EC_ACCESS_METHOD_UNSUPPORTED EC_ACCESS_ORIGIN_DENIED EC_ACCESS_TOKEN_MISSING EC_ACCESS_TOKEN_MALFORMED EC_ACCESS_TOKEN_INVALID EC_ACCESS_TOKEN_REVOKED EC_ACCESS_TOKEN_EXPIRED EC_ACCESS_SCOPES_INSUFFICIENT EC_ACCESS_RATE_LIMITED EC_ACCESS_READONLY EC_ACCESS_DENIED )
12xx - Access errors
View Source
const ( EC_RESOURCE_ID_MISSING = 1300 + iota EC_RESOURCE_ID_MALFORMED EC_RESOURCE_VERSION_MISMATCH EC_RESOURCE_TYPE_MISMATCH EC_RESOURCE_CONFLICT EC_RESOURCE_NOTFOUND EC_RESOURCE_EXISTS EC_RESOURCE_CREATE_FAILED EC_RESOURCE_UPDATE_FAILED EC_RESOURCE_DELETE_FAILED EC_RESOURCE_STATE_UNEXPECTED )
13xx - Resource errors
Variables ¶
View Source
var ( EBadRequest = NewWrappedError(http.StatusBadRequest, "incorrect request syntax") EForbidden = NewWrappedError(http.StatusForbidden, "access forbidden") ENotFound = NewWrappedError(http.StatusNotFound, "resource not found") ENotAllowed = NewWrappedError(http.StatusMethodNotAllowed, "method not allowed") ENotAcceptable = NewWrappedError(http.StatusNotAcceptable, "unsupported response type") EBadMimetype = NewWrappedError(http.StatusUnsupportedMediaType, "unsupported media type") EConflict = NewWrappedError(http.StatusConflict, "resource state conflict") EInternal = NewWrappedError(http.StatusInternalServerError, "internal server error") ERequestTooLarge = NewWrappedError(http.StatusRequestEntityTooLarge, "request size exceeds our limits") ETooManyRequests = NewWrappedError(http.StatusTooManyRequests, "request limit exceeded") ENotImplemented = NewWrappedError(http.StatusNotImplemented, "not implemented") EConnectionClosed = NewWrappedError(499, "connection closed") )
Server Error Reasons
View Source
var ( UserAgent = "Blockwatch-TzIndex/1.0" ApiVersion string )
Functions ¶
func DisableLog ¶
func DisableLog()
DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.
func ParseErrorFromByte ¶
func StateOptions ¶
Respond to requests with the OPTIONS Method.
Types ¶
type ApiErrorWrapper ¶
func NewWrappedApiError ¶
func NewWrappedApiError(status int, msg string) ApiErrorWrapper
type Config ¶
func (Config) ClampExplore ¶
func (Config) ClampExplore64 ¶
func (Config) ClampList64 ¶
type Context ¶
type Context struct { context.Context // request data Request *http.Request ResponseWriter http.ResponseWriter RemoteIP net.IP Cfg *Config Server *RestServer Crawler *etl.Crawler Indexer *etl.Indexer Client *rpc.Client Tip *model.ChainTip Params *rpc.Params // QoS and Debugging RequestID string Log logpkg.Logger // Statistics Now time.Time Expires time.Time Performance *PerformanceCounter // contains filtered or unexported fields }
func NewContext ¶
func NewContext(ctx context.Context, r *http.Request, w http.ResponseWriter, f ApiCall, srv *RestServer) *Context
func (*Context) ParseRequestArgs ¶
func (api *Context) ParseRequestArgs(args interface{})
GET/POST/PATCH/PATCH load data or fail
func (*Context) RequestString ¶
func (*Context) StreamResponseHeaders ¶
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
func NewDispatcher ¶
func NewDispatcher(maxWorkers int, maxQueue int) *Dispatcher
func (*Dispatcher) Run ¶
func (d *Dispatcher) Run()
type Error ¶
type Error struct { Code int `json:"code"` Status int `json:"status"` Message string `json:"message"` Scope string `json:"scope"` Detail string `json:"detail"` RequestId string `json:"request_id,omitempty"` Cause error `json:"-"` Reason string `json:"reason,omitempty"` }
func (*Error) CompleteApiError ¶
func (*Error) MarshalIndent ¶
func (*Error) WithReason ¶
func (*Error) WithRequestId ¶
type ErrorResponse ¶
type ErrorResponse struct {
Errors ErrorList `json:"errors"`
}
type ErrorWrapper ¶
func NewWrappedError ¶
func NewWrappedError(status int, msg string) ErrorWrapper
type HttpConfig ¶
type HttpConfig struct { Addr string `json:"addr"` Port int `json:"port"` MaxWorkers int `json:"max_workers"` MaxQueue int `json:"max_queue"` TimeoutHeader string `json:"timeout_header"` FailHeader string `json:"fail_header"` DegradedHeader string `json:"degraded_header"` LimitHeader string `json:"limit_header"` ReadTimeout time.Duration `json:"read_timeout"` HeaderTimeout time.Duration `json:"header_timeout"` WriteTimeout time.Duration `json:"write_timeout"` KeepAlive time.Duration `json:"keep_alive"` ShutdownTimeout time.Duration `json:"shutdown_timeout"` DefaultListCount uint `json:"default_list_count"` MaxListCount uint `json:"max_list_count"` DefaultExploreCount uint `json:"default_explore_count"` MaxExploreCount uint `json:"max_explore_count"` MaxSeriesDuration time.Duration `json:"max_series_duration"` CorsEnable bool `json:"cors_enable"` CorsOrigin string `json:"cors_origin"` CorsAllowHeaders string `json:"cors_allow_headers"` CorsExposeHeaders string `json:"cors_expose_headers"` CorsMethods string `json:"cors_methods"` CorsMaxAge string `json:"cors_maxage"` CorsCredentials string `json:"cors_credentials"` CacheEnable bool `json:"cache_enable"` CacheControl string `json:"cache_control"` CacheExpires time.Duration `json:"cache_expires"` CacheMaxExpires time.Duration `json:"cache_max"` }
HTTP Server Configuration
func NewHttpConfig ¶
func NewHttpConfig() HttpConfig
func (HttpConfig) Address ¶
func (c HttpConfig) Address() string
func (*HttpConfig) Check ¶
func (cfg *HttpConfig) Check() error
type ParsableRequest ¶
type ParsableRequest interface {
Parse(ctx *Context)
}
type PerformanceCounter ¶
func NewPerformanceCounter ¶
func NewPerformanceCounter(now time.Time) *PerformanceCounter
func (*PerformanceCounter) EndCall ¶
func (p *PerformanceCounter) EndCall()
func (*PerformanceCounter) Since ¶
func (p *PerformanceCounter) Since() time.Duration
func (*PerformanceCounter) StartCall ¶
func (p *PerformanceCounter) StartCall(now time.Time)
func (*PerformanceCounter) WriteResponseHeader ¶
func (p *PerformanceCounter) WriteResponseHeader(w http.ResponseWriter)
func (*PerformanceCounter) WriteResponseTrailer ¶
func (p *PerformanceCounter) WriteResponseTrailer(w http.ResponseWriter)
type RestServer ¶
type RestServer struct {
// contains filtered or unexported fields
}
func New ¶
func New(cfg *Config) (*RestServer, error)
func (*RestServer) IsOffline ¶
func (s *RestServer) IsOffline() bool
func (*RestServer) IsShutdown ¶
func (s *RestServer) IsShutdown() bool
func (*RestServer) SetOffline ¶
func (s *RestServer) SetOffline(off bool)
func (*RestServer) Start ¶
func (s *RestServer) Start()
func (*RestServer) Stop ¶
func (s *RestServer) Stop()
Source Files ¶
Click to show internal directories.
Click to hide internal directories.