Documentation ¶
Index ¶
- Variables
- func Abort(code int)
- func GetFullPath() string
- func HtmlEscape(s string) string
- func SignJWT(headers, payload map[string]string, secret string) string
- func TypeOf(obj any) string
- type App
- func (app *App) Build(addr ...string)
- func (app *App) Listen(host ...string) error
- func (app *App) ListenTLS(certFile string, keyFile string, host ...string) error
- func (app *App) Mount(routers ...*Router)
- func (app *App) ServeHTTP(wr http.ResponseWriter, req *http.Request)
- func (app *App) ShowRoutes()
- func (app *App) UrlFor(name string, external bool, args ...string) string
- type Cors
- type Ctx
- type File
- type Func
- type Header
- type JWT
- type MapCtrl
- type MatchInfo
- type Meth
- type Methods
- type Middlewares
- type Request
- func (r *Request) BasicAuth() (username, password string, ok bool)
- func (r *Request) Cancel()
- func (r *Request) Clone(ctx context.Context) *Request
- func (r *Request) Context() context.Context
- func (r *Request) Ctx() *Ctx
- func (r *Request) ProtoAtLeast(major, minor int) bool
- func (r *Request) RawRequest() *http.Request
- func (r *Request) Referer() string
- func (r *Request) RequestURL() string
- func (r *Request) UrlFor(name string, external bool, args ...string) string
- func (r *Request) UserAgent() string
- func (r *Request) WithContext(ctx context.Context) *Request
- type Response
- func (r *Response) BadRequest(body ...any)
- func (r *Response) Close()
- func (r *Response) Forbidden(body ...any)
- func (r *Response) HTML(body string, code int)
- func (r *Response) ImATaerpot(body ...any)
- func (r *Response) InternalServerError(body ...any)
- func (r *Response) JSON(body any, code int)
- func (r *Response) MethodNotAllowed(body ...any)
- func (r *Response) NotFound(body ...any)
- func (r *Response) Ok(body ...any)
- func (r *Response) Redirect(url string)
- func (r *Response) RenderTemplate(pathToFile string, data ...any)
- func (r *Response) SetCookie(cookie *http.Cookie)
- func (r *Response) TEXT(body string, code int)
- func (r *Response) Unauthorized(body ...any)
- type Route
- func ALL(url string, f Func) *Route
- func CONNECT(url string, f Func) *Route
- func DELETE(url string, f Func) *Route
- func GET(url string, f Func) *Route
- func HEAD(url string, f Func) *Route
- func OPTIONS(url string, f Func) *Route
- func PATCH(url string, f Func) *Route
- func POST(url string, f Func) *Route
- func PUT(url string, f Func) *Route
- func TRACE(url string, f Func) *Route
- type Router
- func (r *Router) ALL(url string, f Func)
- func (r *Router) Add(url, name string, f Func, meths []string)
- func (r *Router) AddAll(routes ...*Route)
- func (r *Router) CONNECT(url string, f Func)
- func (r *Router) DELETE(url string, f Func)
- func (r *Router) GET(url string, f Func)
- func (r *Router) HEAD(url string, f Func)
- func (r *Router) OPTIONS(url string, f Func)
- func (r *Router) PATCH(url string, f Func)
- func (r *Router) POST(url string, f Func)
- func (r *Router) PUT(url string, f Func)
- func (r *Router) TRACE(url string, f Func)
- type Schema
- type Session
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func Abort ¶
func Abort(code int)
Stops execution, cleans up the response body, and writes the StatusCode to the response
func GetFullPath ¶ added in v0.0.9
func GetFullPath() string
func HtmlEscape ¶
Types ¶
type App ¶
type App struct { *Router Env string // environmnt LogFile string // save log info in file SecretKey string // for sign session Servername string // for build url routes and route match StaticFolder string // for serve static files StaticUrlPath string // url uf request static file TemplateFolder string // for render template (html) files Silent bool // don't print logs EnableStatic bool // enable static endpoint for serving static files ListeningInTLS bool // UrlFor return a URl with schema in "https:" BeforeRequest, AfterRequest, TearDownRequest Func // exec after each request, after send to cleint ( this dont has effect in response) // contains filtered or unexported fields }
func (*App) Build ¶ added in v0.0.9
Build the App, but not start serve
example:
func index(ctx slow.Ctx){} // it's work func main() { app := slow.NewApp() app.GET("/",index) app.Build(":5000") app.UrlFor("index",true) } // it's don't work func main() { app := slow.NewApp() app.GET("/",index) app.UrlFor("index",true) }
func (*App) Mount ¶
Register the router in app
func main() { api := slow.NewRouter("api") api.Subdomain = "api" api.Prefix = "/v1" api.post("/products") api.get("/products/{productID:int}") app := slow.NewApp() // This Function app.Mount(getApiRouter) app.Listen() }
func (*App) ServeHTTP ¶
func (app *App) ServeHTTP(wr http.ResponseWriter, req *http.Request)
http.Handler func
type Cors ¶
type Cors struct { MaxAge string // Access-Control-Max-Age AllowOrigin string // Access-Control-Allow-Origin AllowMethods []string // Access-Control-Allow-Methods AllowHeaders []string // Access-Control-Allow-Headers ExposeHeaders []string // Access-Control-Expose-Headers RequestMethod string // Access-Control-Request-Method AllowCredentials bool // Access-Control-Allow-Credentials }
If present on route or router, allows resource sharing between origins
type Ctx ¶
type Header ¶ added in v0.0.11
func (*Header) Add ¶ added in v0.0.11
Add value in a in Header Key. If the key does not exist, it is created
func (*Header) Get ¶ added in v0.0.11
Return a value of Header Key. If the key does not exist, return a empty string
func (*Header) Save ¶ added in v0.0.11
func (h *Header) Save(w http.ResponseWriter)
Write the headers in the response
type Middlewares ¶
type Middlewares []Func
func NewMiddleware ¶
func NewMiddleware(f ...Func) Middlewares
type Request ¶
type Request struct { Header Header Body, Method, RemoteAddr, RequestURI, ContentType string ContentLength int URL *url.URL Form map[string]any Args map[string]string Mime map[string]string Query map[string][]string Files map[string][]*File Cookies map[string]*http.Cookie TransferEncoding []string Proto string // "HTTP/1.0" ProtoMajor int // 1 ProtoMinor int // 0 // contains filtered or unexported fields }
func (*Request) Cancel ¶ added in v0.0.2
func (r *Request) Cancel()
Abort the current request. Server does not respond to client
func (*Request) ProtoAtLeast ¶ added in v0.0.11
func (*Request) RawRequest ¶ added in v0.0.11
func (*Request) UrlFor ¶ added in v0.0.9
URL Builder
app.GET("/", index) app.GET("/login", login) app.UrlFor("login", false, "next", "currentUrl"}) // results: /login?next=currentUrl app.UrlFor("login", true, "token", "foobar"}) // results: http://yourAddress/login?token=foobar // example func index(ctx *slow.Ctx) { req := ctx.Request rsp := ctx.Response userID, ok := ctx.Global["user"] if !ok { next := r.RequestUrl() rsp.Redirect(req.UrlFor("login", true, "next", next)) // redirect to: http://youraddress/login?next=http://yourhost:port/ } ... you code here }
type Response ¶
type Response struct { StatusCode int Body *bytes.Buffer Header Header // contains filtered or unexported fields }
func NewResponse ¶
func NewResponse(wr http.ResponseWriter, ctx *Ctx) *Response
func (*Response) BadRequest ¶
Send a BadRequest ( Status and Text )
func (*Response) Close ¶
func (r *Response) Close()
Halts execution and closes the "response". This does not clear the response body
func (*Response) ImATaerpot ¶
Send a StatusImATaerpot ( Status and Text )
func (*Response) InternalServerError ¶
Send a StatusInternalServerError ( Status and Text )
func (*Response) MethodNotAllowed ¶
Send a StatusMethodNotAllowed ( Status and Text )
func (*Response) RenderTemplate ¶
Parse Html file and send to client
func (*Response) Unauthorized ¶
Send a Unauthorized ( Status and Text )
type Route ¶
type Router ¶
type Router struct { Name, Prefix, Subdomain string Cors *Cors Routes []*Route Middlewares Middlewares // contains filtered or unexported fields }