Documentation ¶
Index ¶
- Constants
- Variables
- func LoadTranslations()
- type Context
- func (c *Context) BodyJson() map[string]any
- 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) EnableTranslations()
- func (c *Context) GetCookie(key string) (string, error)
- func (c *Context) GetUserIP() string
- func (c *Context) Html(template_name string, data map[string]any)
- func (c *Context) Json(body any)
- func (c *Context) JsonIndent(code int, body any)
- func (c *Context) QueryParam(name string) string
- func (c *Context) Redirect(path string)
- 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)
- func (c *Context) Status(code int) *Context
- func (c *Context) StreamResponse(response string) error
- func (c *Context) Text(body string)
- 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)
- type Handler
- type Route
- type Router
- func (router *Router) AddEmbededTemplates(template_embed embed.FS, rootDir string) error
- func (router *Router) AddLocalTemplates(pathToDir string) error
- func (router *Router) DELETE(pattern string, handler Handler, allowed_origines ...string)
- func (r *Router) Embed(staticDir *embed.FS, templateDir *embed.FS)
- func (router *Router) GET(pattern string, handler Handler)
- func (router *Router) LoadEnv(files ...string)
- func (router *Router) NewFuncMap(funcName string, function any)
- func (router *Router) PATCH(pattern string, handler Handler, allowed_origines ...string)
- func (router *Router) POST(pattern string, handler Handler, allowed_origines ...string)
- func (router *Router) PUT(pattern string, handler Handler, allowed_origines ...string)
- func (router *Router) PrintServerStart()
- func (router *Router) Run()
- func (router *Router) RunTLS(certFile string, keyFile string)
- func (router *Router) SSE(pattern string, handler Handler, allowed_origines ...string)
- func (router *Router) ServeEmbededDir(pathLocalDir string, embeded embed.FS, webPath string)
- func (router *Router) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (router *Router) ServeLocalDir(dirPath, webPath string)
- func (router *Router) UseMiddlewares(midws ...func(http.Handler) http.Handler)
- func (router *Router) WS(pattern string, wsHandler WsHandler, allowed_origines ...string)
- type WsContext
- func (c *WsContext) AddClient(key string)
- func (c *WsContext) Broadcast(data any) error
- func (c *WsContext) BroadcastExceptCaller(data map[string]any) error
- func (c *WsContext) Json(data map[string]any) error
- func (c *WsContext) ReceiveJson() (map[string]any, error)
- func (c *WsContext) ReceiveText() (string, error)
- func (c *WsContext) RemoveRequester(name ...string)
- func (c *WsContext) Text(data string) error
- type WsHandler
Constants ¶
const ( GET int = iota POST PUT PATCH DELETE WS SSE )
Variables ¶
var COOKIE_EXPIRE = time.Now().Add(7 * 24 * time.Hour)
COOKIE_EXPIRE global cookie expiry time
var MultipartSize = 10 << 20
var Static embed.FS
var Templates embed.FS
Functions ¶
func LoadTranslations ¶
func LoadTranslations()
Types ¶
type Context ¶
type Context struct { http.ResponseWriter *http.Request Params map[string]string // contains filtered or unexported fields }
Context is a wrapper of responseWriter, request, and params map
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) EnableTranslations ¶
func (c *Context) EnableTranslations()
EnableTranslations get user ip, then location country using nmap, so don't use it if u don't have it install, and then it parse csv file to find the language spoken in this country, to finaly set cookie 'lang' to 'en' or 'fr'...
func (*Context) JsonIndent ¶ added in v0.6.0
JsonIndent return json indented to the client
func (*Context) QueryParam ¶
QueryParam get query param
func (*Context) Redirect ¶ added in v0.6.0
Redirect redirect the client to the specified path with a custom code
func (*Context) ServeEmbededFile ¶
ServeEmbededFile serve an embeded file from handler
func (*Context) StreamResponse ¶
StreamResponse send SSE Streaming Response
type Route ¶
type Route struct { Method string Pattern *regexp.Regexp Handler WsHandler Clients map[string]*websocket.Conn AllowedOrigines []string }
Route
type Router ¶
Router
func (*Router) AddEmbededTemplates ¶
func (*Router) AddLocalTemplates ¶
func (*Router) NewFuncMap ¶
func (*Router) PrintServerStart ¶ added in v0.5.3
func (router *Router) PrintServerStart()
func (*Router) ServeEmbededDir ¶
func (*Router) ServeHTTP ¶
func (router *Router) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP serveHTTP by handling methods,pattern,and params
func (*Router) ServeLocalDir ¶
func (*Router) UseMiddlewares ¶
UseMiddlewares chain global middlewares applied on the router
type WsContext ¶
func (*WsContext) BroadcastExceptCaller ¶
BroadcastExceptCaller send message to all clients in c.Clients
func (*WsContext) ReceiveJson ¶
ReceiveJson receive json from ws and disconnect when stop receiving
func (*WsContext) ReceiveText ¶
ReceiveText receive text from ws and disconnect when stop receiving
func (*WsContext) RemoveRequester ¶
RemoveRequester remove the client from Clients list in context