appsrv

package
v2.3.20181123+incompat... Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2018 License: Apache-2.0 Imports: 28 Imported by: 0

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
	DEFAULT_PROCESS_TIMEOUT     = 15 * time.Second
)
View Source
const (
	HASH_ALG_MD5 int = iota
	HASH_ALG_SHA1
	HASH_ALG_SHA256
)
View Source
const (
	WORKER_STATE_ACTIVE = 0
	WORKER_STATE_DETACH = 1
)

Variables

This section is empty.

Functions

func AppContextDB

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

func Fetch

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

func FetchJSON

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

func FetchStruct

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

func PingHandler

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

func Send

func Send(w http.ResponseWriter, text string)

func SendJSON

func SendJSON(w http.ResponseWriter, obj jsonutils.JSONObject)

func SendStruct

func SendStruct(w http.ResponseWriter, obj interface{})

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 WaitChannel

func WaitChannel(ch chan interface{}) interface{}

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) *Application

func (*Application) AddHandler

func (app *Application) AddHandler(method string, prefix string, handler func(context.Context, http.ResponseWriter, *http.Request))

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)

func (*Application) AddHandler3

func (app *Application) AddHandler3(hi *SHandlerInfo)

func (*Application) AddReverseProxyHandler

func (app *Application) AddReverseProxyHandler(prefix string, ef *proxy.SEndpointFactory)

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) 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) 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{})

type Cache

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

func AppContextCache

func AppContextCache(ctx context.Context) *Cache

func NewCache

func NewCache(size uint32) *Cache

func (*Cache) AtomicGet

func (c *Cache) AtomicGet(key string) interface{}

func (*Cache) AtomicSet

func (c *Cache) AtomicSet(key string, val interface{})

func (*Cache) Get

func (c *Cache) Get(key string) interface{}

func (*Cache) Set

func (c *Cache) Set(key string, val interface{})

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

func (r *RadixNode) Segments() []string

func (*RadixNode) String

func (r *RadixNode) String() string

func (*RadixNode) Walk

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

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

func (r *Ring) Size() int

type SHandlerInfo

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

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

func (hi *SHandlerInfo) SetProcessTimeout(to time.Duration) *SHandlerInfo

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) *SWorkerManager

func (*SWorkerManager) ActiveWorkerCount

func (wm *SWorkerManager) ActiveWorkerCount() int

func (*SWorkerManager) DetachedWorkerCount

func (wm *SWorkerManager) DetachedWorkerCount() int

func (*SWorkerManager) Run

func (wm *SWorkerManager) Run(task func(), worker chan *SWorker, onErr func(error)) bool

func (*SWorkerManager) String

func (wm *SWorkerManager) String() string

type SWorkerManagerStates

type SWorkerManagerStates struct {
	Name            string
	Backlog         int
	MaxWorkerCnt    int
	ActiveWorkerCnt int
	DetachWorkerCnt int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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