appsrv

package
v0.3.11-8 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2024 License: Apache-2.0 Imports: 45 Imported by: 116

Documentation

Index

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 AppContextCache

func AppContextCache(ctx context.Context) *hashcache.Cache

func AppContextDB

func AppContextDB(ctx context.Context) *sql.DB

func DisableClientCache

func DisableClientCache(w http.ResponseWriter)

func Fetch

func Fetch(req *http.Request) ([]byte, error)

func FetchEnv

func FetchEnv(ctx context.Context, w http.ResponseWriter, r *http.Request) (params map[string]string, query jsonutils.JSONObject, body jsonutils.JSONObject)

func FetchJSON

func FetchJSON(req *http.Request) (jsonutils.JSONObject, error)

func FetchStruct

func FetchStruct(req *http.Request, v interface{}) error

func FetchXml

func FetchXml(req *http.Request, target interface{}) error

func GetDBConnectionCount

func GetDBConnectionCount() int

func PingHandler

func PingHandler(ctx context.Context, w http.ResponseWriter, r *http.Request)

func ProcessStatsHandler

func ProcessStatsHandler(ctx context.Context, w http.ResponseWriter, r *http.Request)

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 SendXml

func SendXml(w http.ResponseWriter, hdr http.Header, obj interface{})

func SendXmlWithIndent

func SendXmlWithIndent(w http.ResponseWriter, hdr http.Header, obj interface{}, indent bool)

func SetExitFlag

func SetExitFlag()

func SplitPath

func SplitPath(path string) []string

func StatisticHandler

func StatisticHandler(ctx context.Context, w http.ResponseWriter, r *http.Request)

func VersionHandler

func VersionHandler(ctx context.Context, w http.ResponseWriter, r *http.Request)

func WorkerStatsHandler

func WorkerStatsHandler(ctx context.Context, w http.ResponseWriter, r *http.Request)

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

func (*Application) Stop

func (app *Application) Stop(ctx context.Context) error

type Cors

type Cors struct {
	// Debug logger
	Log *log.Logger
	// contains filtered or unexported fields
}

Cors http handler

func NewCors

func NewCors(options CorsOptions) *Cors

New creates a new Cors handler with the provided options.

func (*Cors) Handler

func (c *Cors) Handler(h http.Handler) http.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 FilterHandler func(ctx context.Context, w http.ResponseWriter, r *http.Request)

type IWorkerTask

type IWorkerTask interface {
	Run()
	Dump() string
}

type RadixNode

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

func NewRadix

func NewRadix() *RadixNode

func (*RadixNode) Add

func (r *RadixNode) Add(segments []string, data interface{}) error

func (*RadixNode) Match

func (r *RadixNode) Match(segments []string, params map[string]string) interface{}

func (*RadixNode) Walk

func (r *RadixNode) Walk(f func(spath string, data interface{}))

type RegexpNode

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

func NewRegexpNode

func NewRegexpNode(node *RadixNode, regStr string) *RegexpNode

type Ring

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

func NewRing

func NewRing(size int) *Ring

func (*Ring) Capacity

func (r *Ring) Capacity() int

func (*Ring) Pop

func (r *Ring) Pop() interface{}

func (*Ring) Push

func (r *Ring) Push(val interface{}) bool

func (*Ring) Range

func (r *Ring) Range(proc func(obj interface{}) bool)

func (*Ring) Size

func (r *Ring) Size() int

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 NewHandlerInfo(method string, path []string, handler func(context.Context, http.ResponseWriter, *http.Request), metadata map[string]interface{}, name string, tags map[string]string) *SHandlerInfo

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) GetName

func (this *SHandlerInfo) GetName(params map[string]string) string

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 SWorker

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

func (*SWorker) Detach

func (worker *SWorker) Detach(reason string)

func (*SWorker) StateStr

func (worker *SWorker) StateStr() string

func (*SWorker) String

func (worker *SWorker) String() string

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 NewWorkerManagerIgnoreOverflow

func NewWorkerManagerIgnoreOverflow(name string, workerCount int, backlog int, dbWorker bool, ignoreOverflow 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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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