Documentation ¶
Index ¶
- Variables
- func CleanRelativePath(path string) (string, error)
- func ClientIP(r *http.Request) string
- func ExtractPagingParams(req *restful.Request, minPageSize, maxPageSize int) (int, int, error)
- func ProjectFrom(ctx context.Context) (string, bool)
- func UserRoleFrom(ctx context.Context) ([]string, bool)
- func UsernameFrom(ctx context.Context) (string, bool)
- func ValidateAlias(fl validator.FieldLevel) bool
- func ValidateEmail(fl validator.FieldLevel) bool
- func ValidateName(fl validator.FieldLevel) bool
- func ValidatePassword(fl validator.FieldLevel) bool
- func ValidateWorkflowMode(fl validator.FieldLevel) bool
- func WithProject(parent context.Context, project string) context.Context
- func WithUserRole(parent context.Context, roles []string) context.Context
- func WithUsername(parent context.Context, username string) context.Context
- type FilterChain
- type FilterFunction
- type MemoryCacheStore
- type ResponseCapture
- type RouteFunction
Constants ¶
This section is empty.
Variables ¶
var Validate = validator.New()
Functions ¶
func CleanRelativePath ¶
CleanRelativePath returns the shortest path name equivalent to path by purely lexical processing. It make sure the provided path is rooted and then uses filepath.Clean and filepath.Rel to make sure the path doesn't include any separators or elements that shouldn't be there like ., .., //.
func ExtractPagingParams ¶
ExtractPagingParams extract `page` and `pageSize` params from request
func ProjectFrom ¶
ProjectFrom extract project from context
func UserRoleFrom ¶
UserRoleFrom extract user role from context
func UsernameFrom ¶
UsernameFrom extract username from context
func ValidateAlias ¶
func ValidateAlias(fl validator.FieldLevel) bool
ValidateAlias custom check alias field
func ValidateEmail ¶
func ValidateEmail(fl validator.FieldLevel) bool
ValidateEmail custom check email field
func ValidateName ¶
func ValidateName(fl validator.FieldLevel) bool
ValidateName custom check name field
func ValidatePassword ¶
func ValidatePassword(fl validator.FieldLevel) bool
ValidatePassword custom check password field
func ValidateWorkflowMode ¶
func ValidateWorkflowMode(fl validator.FieldLevel) bool
ValidateWorkflowMode the sub step mode can be empty.
func WithProject ¶
WithProject carries project in context
func WithUserRole ¶
WithUserRole carries user role in context
Types ¶
type FilterChain ¶
type FilterChain struct {
// contains filtered or unexported fields
}
FilterChain the filter to handle the http request
func NewFilterChain ¶
func NewFilterChain(target RouteFunction, filters ...FilterFunction) *FilterChain
NewFilterChain create a filter chain
func (*FilterChain) ProcessFilter ¶
func (f *FilterChain) ProcessFilter(request *http.Request, response http.ResponseWriter)
ProcessFilter passes the request,response pair through the next of Filters. Each filter can decide to proceed to the next Filter or handle the Response itself.
type FilterFunction ¶
type FilterFunction func(*http.Request, http.ResponseWriter, *FilterChain)
FilterFunction definitions must call ProcessFilter on the FilterChain to pass on the control and eventually call the RouteFunction
type MemoryCacheStore ¶
type MemoryCacheStore struct {
// contains filtered or unexported fields
}
MemoryCacheStore a sample memory cache instance, if data set cache duration, will auto clear after timeout. But, Expired cleanup is not necessarily accurate, it has a 3-second window.
func NewMemoryCacheStore ¶
func NewMemoryCacheStore(ctx context.Context) *MemoryCacheStore
NewMemoryCacheStore memory cache store
func (*MemoryCacheStore) Delete ¶
func (m *MemoryCacheStore) Delete(key interface{})
Delete cache data from store
func (*MemoryCacheStore) Get ¶
func (m *MemoryCacheStore) Get(key interface{}) (value interface{})
Get cache data from store, if not exist or timeout, will return nil
func (*MemoryCacheStore) Put ¶
func (m *MemoryCacheStore) Put(key, value interface{}, cacheDuration time.Duration)
Put cache data, if cacheDuration>0, store will clear data after timeout.
type ResponseCapture ¶
type ResponseCapture struct { http.ResponseWriter // contains filtered or unexported fields }
ResponseCapture capture response and get response info
func NewResponseCapture ¶
func NewResponseCapture(w http.ResponseWriter) *ResponseCapture
NewResponseCapture new response capture
func (ResponseCapture) Bytes ¶
func (c ResponseCapture) Bytes() []byte
Bytes return response body bytes
func (ResponseCapture) Header ¶
func (c ResponseCapture) Header() http.Header
Header return response writer header
func (ResponseCapture) StatusCode ¶
func (c ResponseCapture) StatusCode() int
StatusCode return status code
func (ResponseCapture) Write ¶
func (c ResponseCapture) Write(data []byte) (int, error)
Write write data to response writer and body
func (*ResponseCapture) WriteHeader ¶
func (c *ResponseCapture) WriteHeader(statusCode int)
WriteHeader write header to response writer
type RouteFunction ¶
type RouteFunction func(*http.Request, http.ResponseWriter)
RouteFunction declares the signature of a function that can be bound to a Route.