Documentation ¶
Index ¶
- Constants
- func AppContextCache(ctx context.Context) *hashcache.Cache
- func AppContextDB(ctx context.Context) *sql.DB
- func DisableClientCache(w http.ResponseWriter)
- func Fetch(req *http.Request) ([]byte, error)
- func FetchEnv(ctx context.Context, w http.ResponseWriter, r *http.Request) (params map[string]string, query jsonutils.JSONObject, ...)
- func FetchJSON(req *http.Request) (jsonutils.JSONObject, error)
- func FetchStruct(req *http.Request, v interface{}) error
- func FetchXml(req *http.Request, target interface{}) error
- func GetDBConnectionCount() int
- func PingHandler(ctx context.Context, w http.ResponseWriter, r *http.Request)
- func ProcessStatsHandler(ctx context.Context, w http.ResponseWriter, r *http.Request)
- func Send(w http.ResponseWriter, text string)
- func SendHTML(w http.ResponseWriter, text string)
- func SendHeader(w http.ResponseWriter, hdr http.Header)
- func SendJSON(w http.ResponseWriter, obj jsonutils.JSONObject)
- func SendNoContent(w http.ResponseWriter)
- func SendRedirect(w http.ResponseWriter, redirectUrl string)
- func SendStream(w http.ResponseWriter, isPartial bool, hdr http.Header, stream io.ReadCloser, ...) error
- func SendStruct(w http.ResponseWriter, obj interface{})
- func SendXml(w http.ResponseWriter, hdr http.Header, obj interface{})
- func SendXmlWithIndent(w http.ResponseWriter, hdr http.Header, obj interface{}, indent bool)
- func SetExitFlag()
- func SplitPath(path string) []string
- func StatisticHandler(ctx context.Context, w http.ResponseWriter, r *http.Request)
- func VersionHandler(ctx context.Context, w http.ResponseWriter, r *http.Request)
- func WorkerStatsHandler(ctx context.Context, w http.ResponseWriter, r *http.Request)
- type Application
- func (app *Application) AddDefaultHandler(method string, prefix string, ...)
- func (app *Application) AddHandler(method string, prefix string, ...) *SHandlerInfo
- func (app *Application) AddHandler2(method string, prefix string, ...) *SHandlerInfo
- func (app *Application) AddHandler3(hi *SHandlerInfo) *SHandlerInfo
- func (app *Application) AddReverseProxyHandler(prefix string, ef *proxy.SEndpointFactory, m proxy.RequestManipulator)
- func (app *Application) AddReverseProxyHandlerWithCallbackConfig(prefix string, ef *proxy.SEndpointFactory, m proxy.RequestManipulator, ...)
- func (app *Application) CORSAllowAll()
- func (app *Application) CORSAllowHosts(hosts []string)
- func (app *Application) EnableCORS(options CorsOptions)
- func (app *Application) EnableProfiling()
- func (app *Application) GetContext() context.Context
- func (app *Application) GetName() string
- func (app *Application) ListenAndServe(addr string)
- func (app *Application) ListenAndServeTLS(addr string, certFile, keyFile string)
- func (app *Application) ListenAndServeTLSWithCleanup(addr string, certFile, keyFile string, onStop func())
- func (app *Application) ListenAndServeTLSWithCleanup2(addr string, certFile, keyFile string, onStop func(), isMaster bool)
- func (app *Application) ListenAndServeWithCleanup(addr string, onStop func())
- func (app *Application) ListenAndServeWithoutCleanup(addr, certFile, keyFile string)
- func (app *Application) OnException(exception func(method, path string, body jsonutils.JSONObject, err error)) *Application
- func (app *Application) RegisterMiddleware(f MiddlewareFunc)
- func (app *Application) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (app *Application) SetContext(key appctx.AppContextKey, val interface{})
- func (app *Application) SetDefaultTimeout(to time.Duration) *Application
- func (app *Application) Stop(ctx context.Context) error
- type Cors
- type CorsOptions
- type FilterHandler
- type IWorkerTask
- type MiddlewareFunc
- type RadixNode
- type RegexpNode
- type Ring
- type SAppParams
- type SHandlerInfo
- func (this *SHandlerInfo) FetchProcessTimeout(r *http.Request) time.Duration
- func (hi *SHandlerInfo) GetAppParams(params map[string]string, path []string) *SAppParams
- func (this *SHandlerInfo) GetName(params map[string]string) string
- func (this *SHandlerInfo) GetTags() map[string]string
- func (hi *SHandlerInfo) SetHandler(hand func(context.Context, http.ResponseWriter, *http.Request)) *SHandlerInfo
- func (hi *SHandlerInfo) SetMetadata(meta map[string]interface{}) *SHandlerInfo
- func (hi *SHandlerInfo) SetMethod(method string) *SHandlerInfo
- func (hi *SHandlerInfo) SetName(name string) *SHandlerInfo
- func (hi *SHandlerInfo) SetPath(path string) *SHandlerInfo
- func (hi *SHandlerInfo) SetProcessNoTimeout() *SHandlerInfo
- func (hi *SHandlerInfo) SetProcessTimeout(to time.Duration) *SHandlerInfo
- func (this *SHandlerInfo) SetProcessTimeoutCallback(callback TProcessTimeoutCallback)
- func (hi *SHandlerInfo) SetSkipLog(skip bool) *SHandlerInfo
- func (hi *SHandlerInfo) SetTags(tags map[string]string) *SHandlerInfo
- func (hi *SHandlerInfo) SetWorkerManager(workerMan *SWorkerManager) *SHandlerInfo
- type SWorker
- type SWorkerList
- type SWorkerManager
- func (wm *SWorkerManager) ActiveWorkerCount() int
- func (wm *SWorkerManager) DetachedWorkerCount() int
- func (wm *SWorkerManager) EnableCancelPreviousIdenticalTask()
- func (wm *SWorkerManager) Run(task IWorkerTask, worker chan *SWorker, onErr func(error)) bool
- func (wm *SWorkerManager) String() string
- func (wm *SWorkerManager) UpdateWorkerCount(workerCount int) error
- type SWorkerManagerStates
- type TContentType
- type TMiddleware
- type TProcessTimeoutCallback
Constants ¶
View Source
const ( DEFAULT_BACKLOG = 1024 DEFAULT_IDLE_TIMEOUT = 10 * time.Second DEFAULT_READ_TIMEOUT = 0 DEFAULT_READ_HEADER_TIMEOUT = 10 * time.Second DEFAULT_WRITE_TIMEOUT = 0 // set default process timeout to 60 seconds DEFAULT_PROCESS_TIMEOUT = 60 * time.Second )
View Source
const ( ContentTypeJson = TContentType("Json") ContentTypeForm = TContentType("Form") ContentTypeUnknown = TContentType("Unknown") )
View Source
const ( WORKER_STATE_ACTIVE = 0 WORKER_STATE_DETACH = 1 )
View Source
const (
APP_CONTEXT_KEY_APP_PARAMS = appctx.AppContextKey("app_params")
)
View Source
const (
WATCHDOG_SLEEP_SECONDS = 30
)
Variables ¶
This section is empty.
Functions ¶
func DisableClientCache ¶
func DisableClientCache(w http.ResponseWriter)
func FetchEnv ¶
func FetchEnv(ctx context.Context, w http.ResponseWriter, r *http.Request) (params map[string]string, query jsonutils.JSONObject, body jsonutils.JSONObject)
func FetchStruct ¶
func GetDBConnectionCount ¶
func GetDBConnectionCount() int
func PingHandler ¶
func ProcessStatsHandler ¶
func Send ¶
func Send(w http.ResponseWriter, text string)
func SendHTML ¶
func SendHTML(w http.ResponseWriter, text string)
func SendHeader ¶
func SendHeader(w http.ResponseWriter, hdr http.Header)
func SendJSON ¶
func SendJSON(w http.ResponseWriter, obj jsonutils.JSONObject)
func SendNoContent ¶
func SendNoContent(w http.ResponseWriter)
func SendRedirect ¶
func SendRedirect(w http.ResponseWriter, redirectUrl string)
func SendStream ¶
func SendStream(w http.ResponseWriter, isPartial bool, hdr http.Header, stream io.ReadCloser, sizeBytes int64) error
func SendStruct ¶
func SendStruct(w http.ResponseWriter, obj interface{})
func SendXmlWithIndent ¶
func SendXmlWithIndent(w http.ResponseWriter, hdr http.Header, obj interface{}, indent bool)
func SetExitFlag ¶
func SetExitFlag()
func StatisticHandler ¶
func VersionHandler ¶
func WorkerStatsHandler ¶
Types ¶
type Application ¶
type Application struct {
// contains filtered or unexported fields
}
func AppContextApp ¶
func AppContextApp(ctx context.Context) *Application
func NewApplication ¶
func NewApplication(name string, connMax int, db bool) *Application
func (*Application) AddDefaultHandler ¶
func (app *Application) AddDefaultHandler(method string, prefix string, handler func(context.Context, http.ResponseWriter, *http.Request), name string)
func (*Application) AddHandler ¶
func (app *Application) AddHandler(method string, prefix string, handler func(context.Context, http.ResponseWriter, *http.Request)) *SHandlerInfo
func (*Application) AddHandler2 ¶
func (app *Application) AddHandler2(method string, prefix string, handler func(context.Context, http.ResponseWriter, *http.Request), metadata map[string]interface{}, name string, tags map[string]string) *SHandlerInfo
func (*Application) AddHandler3 ¶
func (app *Application) AddHandler3(hi *SHandlerInfo) *SHandlerInfo
func (*Application) AddReverseProxyHandler ¶
func (app *Application) AddReverseProxyHandler(prefix string, ef *proxy.SEndpointFactory, m proxy.RequestManipulator)
func (*Application) AddReverseProxyHandlerWithCallbackConfig ¶
func (app *Application) AddReverseProxyHandlerWithCallbackConfig(prefix string, ef *proxy.SEndpointFactory, m proxy.RequestManipulator, confCb func(string, *SHandlerInfo) *SHandlerInfo)
func (*Application) CORSAllowAll ¶
func (app *Application) CORSAllowAll()
func (*Application) CORSAllowHosts ¶
func (app *Application) CORSAllowHosts(hosts []string)
func (*Application) EnableCORS ¶
func (app *Application) EnableCORS(options CorsOptions)
func (*Application) EnableProfiling ¶
func (app *Application) EnableProfiling()
func (*Application) GetContext ¶
func (app *Application) GetContext() context.Context
func (*Application) GetName ¶
func (app *Application) GetName() string
func (*Application) ListenAndServe ¶
func (app *Application) ListenAndServe(addr string)
func (*Application) ListenAndServeTLS ¶
func (app *Application) ListenAndServeTLS(addr string, certFile, keyFile string)
func (*Application) ListenAndServeTLSWithCleanup ¶
func (app *Application) ListenAndServeTLSWithCleanup(addr string, certFile, keyFile string, onStop func())
func (*Application) ListenAndServeTLSWithCleanup2 ¶
func (app *Application) ListenAndServeTLSWithCleanup2(addr string, certFile, keyFile string, onStop func(), isMaster bool)
func (*Application) ListenAndServeWithCleanup ¶
func (app *Application) ListenAndServeWithCleanup(addr string, onStop func())
func (*Application) ListenAndServeWithoutCleanup ¶
func (app *Application) ListenAndServeWithoutCleanup(addr, certFile, keyFile string)
func (*Application) OnException ¶
func (app *Application) OnException(exception func(method, path string, body jsonutils.JSONObject, err error)) *Application
func (*Application) RegisterMiddleware ¶
func (app *Application) RegisterMiddleware(f MiddlewareFunc)
func (*Application) ServeHTTP ¶
func (app *Application) ServeHTTP(w http.ResponseWriter, r *http.Request)
func (*Application) SetContext ¶
func (app *Application) SetContext(key appctx.AppContextKey, val interface{})
func (*Application) SetDefaultTimeout ¶
func (app *Application) SetDefaultTimeout(to time.Duration) *Application
type Cors ¶
Cors http handler
func NewCors ¶
func NewCors(options CorsOptions) *Cors
New creates a new Cors handler with the provided options.
func (*Cors) Handler ¶
Handler apply the CORS specification on the request, and add relevant CORS headers as necessary.
func (*Cors) HandlerFunc ¶
func (c *Cors) HandlerFunc(w http.ResponseWriter, r *http.Request)
HandlerFunc provides Martini compatible handler
func (*Cors) ServeHTTP ¶
func (c *Cors) ServeHTTP(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
Negroni compatible interface
type CorsOptions ¶
type CorsOptions struct { // AllowedOrigins is a list of origins a cross-domain request can be executed from. // If the special "*" value is present in the list, all origins will be allowed. // An origin may contain a wildcard (*) to replace 0 or more characters // (i.e.: http://*.domain.com). Usage of wildcards implies a small performance penalty. // Only one wildcard can be used per origin. // Default value is ["*"] AllowedOrigins []string // AllowOriginFunc is a custom function to validate the origin. It take the origin // as argument and returns true if allowed or false otherwise. If this option is // set, the content of AllowedOrigins is ignored. AllowOriginFunc func(origin string) bool // AllowedMethods is a list of methods the client is allowed to use with // cross-domain requests. Default value is simple methods (HEAD, GET and POST). AllowedMethods []string // AllowedHeaders is list of non simple headers the client is allowed to use with // cross-domain requests. // If the special "*" value is present in the list, all headers will be allowed. // Default value is [] but "Origin" is always appended to the list. AllowedHeaders []string // ExposedHeaders indicates which headers are safe to expose to the API of a CORS // API specification ExposedHeaders []string // AllowCredentials indicates whether the request can include user credentials like // cookies, HTTP authentication or client side SSL certificates. AllowCredentials bool // MaxAge indicates how long (in seconds) the results of a preflight request // can be cached MaxAge int // Debugging flag adds additional output to debug server side CORS issues Debug bool }
Options is a configuration container to setup the CORS middleware.
type FilterHandler ¶
type IWorkerTask ¶
type IWorkerTask interface { Run() Dump() string }
type MiddlewareFunc ¶
type RadixNode ¶
type RadixNode struct {
// contains filtered or unexported fields
}
type RegexpNode ¶
type RegexpNode struct {
// contains filtered or unexported fields
}
func NewRegexpNode ¶
func NewRegexpNode(node *RadixNode, regStr string) *RegexpNode
type SAppParams ¶
type SAppParams struct { Name string SkipLog bool SkipTrace bool Params map[string]string Path []string Body jsonutils.JSONObject Request *http.Request Response http.ResponseWriter OverrideResponseBodyWrapper bool }
func AppContextGetParams ¶
func AppContextGetParams(ctx context.Context) *SAppParams
type SHandlerInfo ¶
type SHandlerInfo struct {
// contains filtered or unexported fields
}
func NewHandlerInfo ¶
func (*SHandlerInfo) FetchProcessTimeout ¶
func (this *SHandlerInfo) FetchProcessTimeout(r *http.Request) time.Duration
func (*SHandlerInfo) GetAppParams ¶
func (hi *SHandlerInfo) GetAppParams(params map[string]string, path []string) *SAppParams
func (*SHandlerInfo) GetTags ¶
func (this *SHandlerInfo) GetTags() map[string]string
func (*SHandlerInfo) SetHandler ¶
func (hi *SHandlerInfo) SetHandler(hand func(context.Context, http.ResponseWriter, *http.Request)) *SHandlerInfo
func (*SHandlerInfo) SetMetadata ¶
func (hi *SHandlerInfo) SetMetadata(meta map[string]interface{}) *SHandlerInfo
func (*SHandlerInfo) SetMethod ¶
func (hi *SHandlerInfo) SetMethod(method string) *SHandlerInfo
func (*SHandlerInfo) SetName ¶
func (hi *SHandlerInfo) SetName(name string) *SHandlerInfo
func (*SHandlerInfo) SetPath ¶
func (hi *SHandlerInfo) SetPath(path string) *SHandlerInfo
func (*SHandlerInfo) SetProcessNoTimeout ¶
func (hi *SHandlerInfo) SetProcessNoTimeout() *SHandlerInfo
func (*SHandlerInfo) SetProcessTimeout ¶
func (hi *SHandlerInfo) SetProcessTimeout(to time.Duration) *SHandlerInfo
func (*SHandlerInfo) SetProcessTimeoutCallback ¶
func (this *SHandlerInfo) SetProcessTimeoutCallback(callback TProcessTimeoutCallback)
func (*SHandlerInfo) SetSkipLog ¶
func (hi *SHandlerInfo) SetSkipLog(skip bool) *SHandlerInfo
func (*SHandlerInfo) SetTags ¶
func (hi *SHandlerInfo) SetTags(tags map[string]string) *SHandlerInfo
func (*SHandlerInfo) SetWorkerManager ¶
func (hi *SHandlerInfo) SetWorkerManager(workerMan *SWorkerManager) *SHandlerInfo
type SWorkerList ¶
type SWorkerList struct {
// contains filtered or unexported fields
}
type SWorkerManager ¶
type SWorkerManager struct {
// contains filtered or unexported fields
}
func NewWorkerManager ¶
func NewWorkerManager(name string, workerCount int, backlog int, dbWorker bool) *SWorkerManager
func (*SWorkerManager) ActiveWorkerCount ¶
func (wm *SWorkerManager) ActiveWorkerCount() int
func (*SWorkerManager) DetachedWorkerCount ¶
func (wm *SWorkerManager) DetachedWorkerCount() int
func (*SWorkerManager) EnableCancelPreviousIdenticalTask ¶
func (wm *SWorkerManager) EnableCancelPreviousIdenticalTask()
func (*SWorkerManager) Run ¶
func (wm *SWorkerManager) Run(task IWorkerTask, worker chan *SWorker, onErr func(error)) bool
func (*SWorkerManager) String ¶
func (wm *SWorkerManager) String() string
func (*SWorkerManager) UpdateWorkerCount ¶
func (wm *SWorkerManager) UpdateWorkerCount(workerCount int) error
type SWorkerManagerStates ¶
type SWorkerManagerStates struct { Name string Backlog int QueueCnt int MaxWorkerCnt int ActiveWorkerCnt int DetachWorkerCnt int DbWorker bool AllowOverflow bool }
func (SWorkerManagerStates) IsBusy ¶
func (s SWorkerManagerStates) IsBusy() bool
type TContentType ¶
type TContentType string
type TMiddleware ¶
type TMiddleware func(handler FilterHandler) FilterHandler
type TProcessTimeoutCallback ¶
type TProcessTimeoutCallback func(*SHandlerInfo, *http.Request) time.Duration
Source Files ¶
Click to show internal directories.
Click to hide internal directories.