Documentation ¶
Index ¶
- Constants
- Variables
- func BeforeRenderHtml(uniqueName string, fn func(c *Context, data *map[string]any))
- func CheckAndInstallSwagger() error
- func ClearTraces()
- func ConfigureExport(endpoint string, exportType ExportType)
- func CopyFile(src, dst string, BUFFERSIZE int64) error
- func DisableTracing()
- func EnableTracing(handler TraceHandler)
- func ExecuteRawHtml(rawTemplateName string, data map[string]any) (string, error)
- func GenerateGoDocsComments(pkgName ...string)
- func GenerateID() string
- func GenerateJsonDocs(entryDocsFile ...string)
- func GenerateUUID() (string, error)
- func GetPrivateIp() string
- func GetRouters() *kmap.SafeMap[string, *Router]
- func GetTraces() map[string][]*Span
- func Graceful(f func() error) error
- func Gzip() func(http.Handler) http.Handler
- func IgnoreLogsEndpoints(pathContain ...string)
- func IgnoreTracingEndpoints(pathContain ...string)
- func IsSupervisor() bool
- func Limiter(conf *ConfigLimiter) func(http.Handler) http.Handler
- func Logs(callback ...func(method, path, remote string, status int, took time.Duration)) func(http.Handler) http.Handler
- func NewFuncMap(funcMap map[string]any)
- func SaveMultipartFile(fh *multipart.FileHeader, path string) (err error)
- func SaveRawHtml(templateRaw string, templateName string)
- func SetMaxTraces(max int)
- func SetSSLEmail(email string)
- func SetSSLMode(ProdOrDev string)
- func SliceContains[T comparable](elems []T, vs ...T) bool
- func StringContains(s string, subs ...string) bool
- func ToSlug(s string) (string, error)
- func TracingMiddleware(next http.Handler) http.Handler
- func UpgradeConnection(w http.ResponseWriter, r *http.Request, responseHeader http.Header) (*ws.Conn, error)
- type Backend
- type BackendOpt
- type CircuitBreaker
- type Config
- type ConfigLimiter
- type Context
- func (c *Context) AddHeader(key, value string)
- func (c *Context) AddSSEHeaders()
- func (c *Context) BindBody(strctPointer any, isXML ...bool) error
- func (c *Context) BodyJson() map[string]any
- func (c *Context) BodyStruct(dest any) error
- func (c *Context) BodyText() string
- func (c *Context) Context() context.Context
- func (c *Context) DeleteCookie(key string)
- func (c *Context) DeleteFile(path string) error
- func (c *Context) Download(data_bytes []byte, asFilename string)
- func (c *Context) EarlyHint(hints ...EarlyHint)
- func (c *Context) Error(errorMsg any)
- func (c *Context) Flush() bool
- func (c *Context) GetCookie(key string) (string, error)
- func (c *Context) GetKey(key string) (any, bool)
- func (c *Context) GetKeyAs(key string, ptrStruct any) bool
- func (c *Context) GetUserIP() string
- func (c *Context) Html(template_name string, data map[string]any)
- func (c *Context) IsAuthenticated(key ...string) bool
- func (c *Context) Json(data any)
- func (c *Context) JsonIndent(data any)
- func (c *Context) MatchedPath() string
- func (c *Context) NamedRawHtml(rawTemplateName string, data map[string]any) error
- func (c *Context) Param(name string) string
- func (c *Context) ParseMultipartForm(maxSize ...int64) (formData url.Values, formFiles map[string][]*multipart.FileHeader)
- func (c *Context) QueryParam(name string) string
- func (c *Context) RawHtml(rawTemplate string, data map[string]any) error
- func (c *Context) Redirect(path string)
- func (c *Context) Return(kvs ...any)
- func (c *Context) SaveFile(fileheader *multipart.FileHeader, path string) error
- func (c *Context) ServeEmbededFile(content_type string, embed_file []byte)
- func (c *Context) ServeFile(content_type, path_to_file string)
- func (c *Context) SetCookie(key, value string, maxAge ...time.Duration)
- func (c *Context) SetHeader(key, value string)
- func (c *Context) SetKey(key string, value any)
- func (c *Context) SetStatus(statusCode int)
- func (c *Context) SliceParams() Params
- func (c *Context) Status(code int) *Context
- func (c *Context) Stream(response string) error
- func (c *Context) Success(successMsg any)
- func (c *Context) Text(body string)
- func (c *Context) UpgradeConnection() (*ws.Conn, error)
- func (c *Context) UploadFile(received_filename, folder_out string, acceptedFormats ...string) (string, []byte, error)
- func (c *Context) UploadFiles(received_filenames []string, folder_out string, acceptedFormats ...string) ([]string, [][]byte, error)
- func (c *Context) User(key ...string) (any, bool)
- func (c *Context) WithPushOptions(opts *http.PushOptions)
- type ContextKey
- type DocsGeneralInfo
- type DocsIn
- type DocsOut
- type DocsRoute
- type EarlyHint
- type EarlyHintType
- type ExportType
- type GroupRouter
- func (gr *GroupRouter) Delete(pattern string, handler Handler, origines ...string) *Route
- func (gr *GroupRouter) Get(pattern string, handler Handler, origines ...string) *Route
- func (gr *GroupRouter) Head(pattern string, handler Handler, origines ...string) *Route
- func (gr *GroupRouter) Options(pattern string, handler Handler, origines ...string) *Route
- func (gr *GroupRouter) Patch(pattern string, handler Handler, origines ...string) *Route
- func (gr *GroupRouter) Post(pattern string, handler Handler, origines ...string) *Route
- func (gr *GroupRouter) Put(pattern string, handler Handler, origines ...string) *Route
- func (gr *GroupRouter) Use(middlewares ...func(Handler) Handler)
- type Handler
- type LimitStrategy
- type LoadBalancer
- type Param
- type Params
- type PathConfig
- type Route
- func (r *Route) Accept(accept string) *Route
- func (r *Route) Description(description string) *Route
- func (r *Route) In(docsParam ...string) *Route
- func (r *Route) Out(sucessResponse string, failureResponses ...string) *Route
- func (r *Route) Produce(produce string) *Route
- func (r *Route) Summary(summary string) *Route
- func (r *Route) Tags(tags ...string) *Route
- type Router
- func (router *Router) Address() string
- func (router *Router) CreateServerCerts(domainName string, subDomains ...string) (*autocert.Manager, *tls.Config)
- func (r *Router) Delete(path string, handler Handler, origines ...string) *Route
- func (router *Router) EmbededStatics(embeded embed.FS, pathLocalDir, webPath string, ...) error
- func (router *Router) EmbededTemplates(template_embed embed.FS, rootDir string) error
- func (router *Router) EnableDomainCheck()
- func (r *Router) Get(path string, handler Handler, origines ...string) *Route
- func (router *Router) Group(prefix string) *GroupRouter
- func (r *Router) Handle(method, path string, handler Handler, origines ...string) *Route
- func (r *Router) HandlerFunc(method, path string, handler http.HandlerFunc, origines ...string) *Route
- func (r *Router) Head(path string, handler Handler, origines ...string) *Route
- func (router *Router) Host() string
- func (router *Router) IsTls() bool
- func (router *Router) LoadBalancer(pattern string, backends ...BackendOpt) error
- func (router *Router) LocalStatics(dirPath, webPath string, handlerMiddlewares ...func(handler Handler) Handler) error
- func (router *Router) LocalTemplates(pathToDir string) error
- func (r *Router) Lookup(method, path string) (Handler, Params, bool, string)
- func (router *Router) NewFuncMap(funcMap map[string]any)
- func (router *Router) NewTemplateFunc(funcName string, function any)
- func (router *Router) OnShutdown(fn func() error)
- func (r *Router) Options(path string, handler Handler, origines ...string) *Route
- func (r *Router) Patch(path string, handler Handler, origines ...string) *Route
- func (router *Router) Port() string
- func (r *Router) Post(path string, handler Handler, origines ...string) *Route
- func (r *Router) PrintTree()
- func (r *Router) Put(path string, handler Handler, origines ...string) *Route
- func (router *Router) Restart(cleanupCallbacks ...func() error) error
- func (router *Router) ReverseProxy(host, toURL string) (newRouter *Router)
- func (router *Router) Run()
- func (router *Router) RunAutoTLS()
- func (router *Router) RunTLS()
- func (router *Router) ServeEmbededFile(file []byte, endpoint, contentType string)
- func (r *Router) ServeFiles(path string, root http.FileSystem)
- func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (router *Router) ServeLocalFile(file, endpoint, contentType string)
- func (router *Router) Signal() chan os.Signal
- func (router *Router) Stop()
- func (r *Router) ToMap() map[string]*node
- func (router *Router) Use(midws ...func(http.Handler) http.Handler)
- func (router *Router) WithDocs(genJsonDocs bool, genGoDocs ...bool) *Router
- func (router *Router) WithMetrics(httpHandler http.Handler, path ...string)
- func (router *Router) WithPprof(path ...string)
- type RouterConfig
- type Span
- func (s *Span) Duration() time.Duration
- func (s *Span) End()
- func (s *Span) EndTime() time.Time
- func (s *Span) Error() error
- func (s *Span) Name() string
- func (s *Span) ParentID() string
- func (s *Span) SetDuration(d time.Duration)
- func (s *Span) SetError(err error)
- func (s *Span) SetStatusCode(code int)
- func (s *Span) SetTag(key, value string)
- func (s *Span) SpanID() string
- func (s *Span) StartTime() time.Time
- func (s *Span) StatusCode() int
- func (s *Span) Tags() map[string]string
- func (s *Span) TraceID() string
- type StatusRecorder
- type TraceHandler
- type Tracer
Constants ¶
const ( StateClosed = iota StateOpen StateHalfOpen )
const ( // Export types ExportTypeJaeger ExportType = "jaeger" ExportTypeTempo ExportType = "tempo" ExportTypeZipkin ExportType = "zipkin" ExportTypeDatadog ExportType = "datadog" ExportTypeNewRelic ExportType = "newrelic" ExportTypeHoneycomb ExportType = "honeycomb" ExportTypeOTLP ExportType = "otlp" // OpenTelemetry Protocol ExportTypeSignoz ExportType = "signoz" // Open source alternative // Default endpoints DefaultJaegerEndpoint = "http://localhost:14268/api/traces" DefaultTempoEndpoint = "http://localhost:9411/api/v2/spans" DefaultZipkinEndpoint = "http://localhost:9411/api/v2/spans" DefaultDatadogEndpoint = "https://trace.agent.datadoghq.com" DefaultNewRelicEndpoint = "https://trace-api.newrelic.com/trace/v1" DefaultHoneycombEndpoint = "https://api.honeycomb.io/1/traces" DefaultOTLPEndpoint = "http://localhost:4318/v1/traces" DefaultSignozEndpoint = "http://localhost:4318/v1/traces" // DefaultMaxTraces is the default maximum number of traces to keep in memory DefaultMaxTraces = 500 )
Variables ¶
var ( // docs DocsOutJson = "." DocsEntryFile = "ksmuxdocs/ksmuxdocs.go" OnDocsGenerationReady = func() {} // ctx cookies COOKIES_Expires = 24 * 7 * time.Hour COOKIES_SameSite = http.SameSiteStrictMode COOKIES_HttpOnly = true COOKIES_SECURE = true )
var AutoCertRegexHostPolicy = false
var Cors = func(allowed ...string) func(http.Handler) http.Handler { firstRouter.state.corsEnabled = true if len(allowed) == 0 { allowed = append(allowed, "*") } for i := range allowed { if allowed[i] == "*" { continue } allowed[i] = strings.ReplaceAll(allowed[i], "localhost", "127.0.0.1") if !strings.HasPrefix(allowed[i], "http") { allowed[i] = "http://" + allowed[i] } } return func(h http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if allowed[0] == "*" { w.Header().Set("Access-Control-Allow-Origin", r.Header.Get("Origin")) } else { w.Header().Set("Access-Control-Allow-Origin", allowed[0]) } w.Header().Set("Access-Control-Allow-Methods", "*") w.Header().Set("Access-Control-Allow-Credentials", "true") w.Header().Set("Access-Control-Allow-Headers", "*") if r.Method == "OPTIONS" { w.Header().Set("Access-Control-Allow-Headers", "Access-Control-Allow-Headers, Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers, X-Korm, Authorization, Token, X-Token") w.WriteHeader(http.StatusNoContent) return } h.ServeHTTP(w, r) }) } }
var DocsGeneralDefaults = DocsGeneralInfo{
Title: "Korm Api Documentation",
Version: "1.0.0",
Host: "localhost:9313",
BasePath: "/",
Description: "Swagger Api Documentation for Korm",
TermsOfService: "http://swagger.io/terms/",
ContactName: "API Support",
ContactUrl: "https://kamalshkeir.dev",
ContactEmail: "support@email.com",
LicenseName: "Apache 2.0",
LicenseUrl: "http://www.apache.org/licenses/LICENSE-2.0.html",
}
var MatchedRoutePathParam = "$ksmuxdone"
MatchedRoutePathParam is the Param name under which the path of the matched route is stored, if Router.SaveMatchedPath is set.
Functions ¶
func BeforeRenderHtml ¶
BeforeRenderHtml executed before every html render, you can use reqCtx.Value(key).(type.User) for example and add data to templates globaly
func CheckAndInstallSwagger ¶
func CheckAndInstallSwagger() error
func ConfigureExport ¶ added in v0.4.3
func ConfigureExport(endpoint string, exportType ExportType)
ConfigureExport sets the export endpoint and type
func EnableTracing ¶ added in v0.4.3
func EnableTracing(handler TraceHandler)
EnableTracing enables tracing with an optional custom handler
func ExecuteRawHtml ¶
func GenerateGoDocsComments ¶
func GenerateGoDocsComments(pkgName ...string)
func GenerateID ¶ added in v0.4.3
func GenerateID() string
GenerateID generates a unique ID for traces and spans
func GenerateJsonDocs ¶
func GenerateJsonDocs(entryDocsFile ...string)
func GenerateUUID ¶
func GetPrivateIp ¶
func GetPrivateIp() string
func IgnoreLogsEndpoints ¶ added in v0.0.5
func IgnoreLogsEndpoints(pathContain ...string)
func IgnoreTracingEndpoints ¶ added in v0.4.3
func IgnoreTracingEndpoints(pathContain ...string)
IgnoreTracingEndpoints allows adding paths to ignore in tracing
func IsSupervisor ¶ added in v0.6.8
func IsSupervisor() bool
IsSupervisor returns true if current process is the supervisor
func NewFuncMap ¶ added in v0.0.6
func SaveMultipartFile ¶
func SaveMultipartFile(fh *multipart.FileHeader, path string) (err error)
SaveMultipartFile Save MultipartFile
func SaveRawHtml ¶
SaveRawHtml save templateRaw as templateName to be able to use it like c.RawHtml
func SetMaxTraces ¶ added in v0.4.4
func SetMaxTraces(max int)
SetMaxTraces sets the maximum number of traces to keep in memory
func SetSSLEmail ¶ added in v0.2.2
func SetSSLEmail(email string)
func SetSSLMode ¶ added in v0.2.2
func SetSSLMode(ProdOrDev string)
func SliceContains ¶
func SliceContains[T comparable](elems []T, vs ...T) bool
func StringContains ¶
func TracingMiddleware ¶ added in v0.4.3
TracingMiddleware adds tracing to all routes
Types ¶
type BackendOpt ¶ added in v0.5.3
type CircuitBreaker ¶ added in v0.5.3
type CircuitBreaker struct {
// contains filtered or unexported fields
}
func NewCircuitBreaker ¶ added in v0.5.3
func NewCircuitBreaker() *CircuitBreaker
func (*CircuitBreaker) IsAvailable ¶ added in v0.5.3
func (cb *CircuitBreaker) IsAvailable() bool
func (*CircuitBreaker) RecordFailure ¶ added in v0.5.3
func (cb *CircuitBreaker) RecordFailure()
func (*CircuitBreaker) RecordSuccess ¶ added in v0.5.3
func (cb *CircuitBreaker) RecordSuccess()
type ConfigLimiter ¶ added in v0.0.7
type ConfigLimiter struct { Message string // default "TOO MANY REQUESTS" RateEvery time.Duration // default 10 min BurstsN int // default 100 CheckEvery time.Duration // default 5 min BlockDuration time.Duration // default 10 min OnLimitReached func(c *Context) // Custom handler for when limit is reached Strategy LimitStrategy // Strategy for rate limiting HeaderName string // Header name for LimitByHeader strategy PathConfigs []PathConfig // Path-specific configurations }
type Context ¶
type Context struct { http.ResponseWriter *http.Request Params Params // contains filtered or unexported fields }
func (*Context) AddSSEHeaders ¶ added in v0.0.4
func (c *Context) AddSSEHeaders()
func (*Context) BodyStruct ¶ added in v0.3.1
BodyStruct decodes request body into struct
func (*Context) DeleteCookie ¶
DeleteCookie delete cookie with specific key
func (*Context) Download ¶
Download download data_bytes(content) asFilename(test.json,data.csv,...) to the client
func (*Context) IsAuthenticated ¶
func (*Context) JsonIndent ¶
JsonIndent return json indented to the client
func (*Context) MatchedPath ¶
func (*Context) NamedRawHtml ¶
NamedRawHtml render rawTemplateName with data using go engine, make sure to save the html using ksmux.SaveRawHtml outside the handler
func (*Context) ParseMultipartForm ¶
func (*Context) QueryParam ¶
QueryParam get query param
func (*Context) RawHtml ¶
NamedRawHtml render rawTemplateName with data using go engine, make sure to save the html using ksmux.SaveRawHtml outside the handler
func (*Context) Redirect ¶
Redirect redirect the client to the specified path with a custom code, default status 307
func (*Context) SaveFile ¶
func (c *Context) SaveFile(fileheader *multipart.FileHeader, path string) error
SaveFile save file to path
func (*Context) ServeEmbededFile ¶
ServeEmbededFile serve an embeded file from handler
func (*Context) SliceParams ¶
func (*Context) UpgradeConnection ¶ added in v0.0.4
func (*Context) UploadFile ¶
func (c *Context) UploadFile(received_filename, folder_out string, acceptedFormats ...string) (string, []byte, error)
UploadFile upload received_filename into folder_out and return url,fileByte,error
func (*Context) UploadFiles ¶
func (*Context) WithPushOptions ¶ added in v0.1.3
func (c *Context) WithPushOptions(opts *http.PushOptions)
type ContextKey ¶
type ContextKey string
type DocsGeneralInfo ¶
type DocsOut ¶
type EarlyHint ¶ added in v0.2.6
type EarlyHint struct { Type EarlyHintType URL string Rel string }
type EarlyHintType ¶ added in v0.2.6
type EarlyHintType string
var ( EarlyHint_OBJECT EarlyHintType = "object" EarlyHint_IMAGE EarlyHintType = "image" EarlyHint_AUDIO EarlyHintType = "audio" EarlyHint_TRACK EarlyHintType = "track" EarlyHint_VIDEO EarlyHintType = "video" EarlyHint_DOCUMENT EarlyHintType = "document" EarlyHint_EMBED EarlyHintType = "embed" EarlyHint_STYLE EarlyHintType = "style" EarlyHint_SCRIPT EarlyHintType = "script" EarlyHint_FETCH EarlyHintType = "fetch" EarlyHint_FONT EarlyHintType = "font" EarlyHint_WORKER EarlyHintType = "worker" )
type ExportType ¶ added in v0.4.3
type ExportType string
ExportType defines the type of trace exporter
type GroupRouter ¶
func (*GroupRouter) Delete ¶
func (gr *GroupRouter) Delete(pattern string, handler Handler, origines ...string) *Route
func (*GroupRouter) Get ¶
func (gr *GroupRouter) Get(pattern string, handler Handler, origines ...string) *Route
func (*GroupRouter) Head ¶
func (gr *GroupRouter) Head(pattern string, handler Handler, origines ...string) *Route
func (*GroupRouter) Options ¶
func (gr *GroupRouter) Options(pattern string, handler Handler, origines ...string) *Route
func (*GroupRouter) Patch ¶
func (gr *GroupRouter) Patch(pattern string, handler Handler, origines ...string) *Route
func (*GroupRouter) Post ¶
func (gr *GroupRouter) Post(pattern string, handler Handler, origines ...string) *Route
func (*GroupRouter) Put ¶
func (gr *GroupRouter) Put(pattern string, handler Handler, origines ...string) *Route
func (*GroupRouter) Use ¶
func (gr *GroupRouter) Use(middlewares ...func(Handler) Handler)
Use chain handler middlewares
type Handler ¶
type Handler func(c *Context)
Handler is a function that can be registered to a route to handle HTTP requests. Like http.HandlerFunc, but has a third parameter for the values of wildcards (path variables).
type LimitStrategy ¶ added in v0.5.3
type LimitStrategy int
LimitStrategy defines how we identify requests for rate limiting
const ( LimitByIP LimitStrategy = iota LimitByPath LimitByHeader LimitByIPAndPath )
type LoadBalancer ¶ added in v0.5.3
type LoadBalancer struct {
// contains filtered or unexported fields
}
func (*LoadBalancer) AddBackend ¶ added in v0.5.3
func (lb *LoadBalancer) AddBackend(rawURL string, mid ...Handler) error
func (*LoadBalancer) NextBackend ¶ added in v0.5.3
func (lb *LoadBalancer) NextBackend(path string) *Backend
Round Robin Selection
func (*LoadBalancer) RemoveDeadBackends ¶ added in v0.5.5
func (lb *LoadBalancer) RemoveDeadBackends()
type Params ¶
type Params []Param
Params is a Param-slice, as returned by the router. The slice is ordered, the first URL parameter is also the first slice value. It is therefore safe to read values by the index.
func GetParamsFromCtx ¶
GetParamsFromCtx get params from ctx for http.Handler
type PathConfig ¶ added in v0.5.3
type Route ¶
func (*Route) Description ¶
func (*Route) In ¶
In must be like "name in typePath required 'desc'" or you can use ksmux.DocsIn.String() method
func (*Route) Out ¶
Out must be like "200 {object}/{array}/{string} app1.Account/string 'okifstring'" or you can use ksmux.DocsOut.String() method
type Router ¶
type Router struct { Server *http.Server AutoCertManager *autocert.Manager Config *Config RouterConfig *RouterConfig // contains filtered or unexported fields }
Router is a http.Handler which can be used to dispatch requests to different handler functions via configurable routes
func GetFirstRouter ¶ added in v0.5.5
func GetFirstRouter() *Router
func New ¶
New returns a new initialized Router. Path auto-correction, including trailing slashes, is enabled by default.
func (*Router) CreateServerCerts ¶ added in v0.2.2
func (*Router) EmbededStatics ¶
func (*Router) EmbededTemplates ¶
func (*Router) EnableDomainCheck ¶ added in v0.0.3
func (router *Router) EnableDomainCheck()
EnableDomainCheck enable only the domain check from ksmux methods Get,Post,... (does not add cors middleware)
func (*Router) Group ¶
func (router *Router) Group(prefix string) *GroupRouter
Group create group path
func (*Router) Handle ¶
Handle registers a new request handler with the given path and method.
For GET, POST, PUT, PATCH and DELETE requests the respective shortcut functions can be used.
This function is intended for bulk loading and to allow the usage of less frequently used, non-standardized or custom methods (e.g. for internal communication with a proxy).
func (*Router) HandlerFunc ¶
func (r *Router) HandlerFunc(method, path string, handler http.HandlerFunc, origines ...string) *Route
HandlerFunc is an adapter which allows the usage of an http.HandlerFunc as a request handler.
func (*Router) LoadBalancer ¶ added in v0.5.3
func (router *Router) LoadBalancer(pattern string, backends ...BackendOpt) error
func (*Router) LocalStatics ¶
func (*Router) LocalTemplates ¶
func (*Router) Lookup ¶
Lookup allows the manual lookup of a method + path combo. This is e.g. useful to build a framework around this router. If the path was found, it returns the handler function and the path parameter values. Otherwise the third return value indicates whether a redirection to the same path with an extra / without the trailing slash should be performed.
func (*Router) NewFuncMap ¶
func (*Router) NewTemplateFunc ¶
func (*Router) OnShutdown ¶ added in v0.5.5
func (*Router) Restart ¶ added in v0.5.5
Restart shuts down the current server and lets supervisor start a new instance
func (*Router) ReverseProxy ¶
func (*Router) RunAutoTLS ¶
func (router *Router) RunAutoTLS()
RunAutoTLS HTTPS server generate certificates and handle renew
func (*Router) ServeEmbededFile ¶
func (*Router) ServeFiles ¶
func (r *Router) ServeFiles(path string, root http.FileSystem)
ServeFiles serves files from the given file system root. The path must end with "/*filepath", files are then served from the local path /defined/root/dir/*filepath. For example if root is "/etc" and *filepath is "passwd", the local file "/etc/passwd" would be served. Internally a http.FileServer is used, therefore http.NotFound is used instead of the Router's NotFound handler. To use the operating system's file system implementation, use http.Dir:
router.ServeFiles("/src/*filepath", http.Dir("/var/www"))
func (*Router) ServeHTTP ¶
func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP makes the router implement the http.Handler interface.
func (*Router) ServeLocalFile ¶
func (*Router) Stop ¶ added in v0.5.6
func (router *Router) Stop()
Stop gracefully shuts down the server. It triggers the shutdown process by sending an interrupt signal and waits for completion.
func (*Router) WithDocs ¶
WithDocs check and install swagger, and generate json and go docs at the end , after the server run, you can use ksmux.OnDocsGenerationReady() genGoDocs default to true if genJsonDocs
func (*Router) WithMetrics ¶
WithMetrics take prometheus handler and serve metrics on path or default /metrics
type RouterConfig ¶ added in v0.5.5
type RouterConfig struct { ReadTimeout time.Duration WriteTimeout time.Duration IdleTimeout time.Duration GlobalOPTIONS http.Handler NotFound http.Handler MethodNotAllowed http.Handler PanicHandler func(http.ResponseWriter, *http.Request, interface{}) SaveMatchedPath bool RedirectTrailingSlash bool RedirectFixedPath bool HandleMethodNotAllowed bool HandleOPTIONS bool // contains filtered or unexported fields }
type Span ¶ added in v0.4.3
type Span struct {
// contains filtered or unexported fields
}
Span represents a single operation within a trace
func (*Span) SetDuration ¶ added in v0.4.5
SetStatusCode sets the HTTP status code
func (*Span) SetStatusCode ¶ added in v0.4.3
SetStatusCode sets the HTTP status code
func (*Span) StatusCode ¶ added in v0.4.3
type StatusRecorder ¶
type StatusRecorder struct { http.ResponseWriter Status int }
func (*StatusRecorder) Flush ¶
func (r *StatusRecorder) Flush()
func (*StatusRecorder) Hijack ¶
func (r *StatusRecorder) Hijack() (net.Conn, *bufio.ReadWriter, error)
func (*StatusRecorder) WriteHeader ¶
func (r *StatusRecorder) WriteHeader(status int)
type TraceHandler ¶ added in v0.4.3
type TraceHandler interface {
HandleTrace(span *Span)
}
TraceHandler is an interface for custom trace handling