Documentation ¶
Index ¶
- Variables
- func Abort(code int)
- func GetFullPath() string
- func MountSchemaFromRequest(f *c3po.Fielder, req *Request) (reflect.Value, any)
- func ServeFile(ctx *Ctx, pathToFile ...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)
- func (app *App) Mount(routers ...*Router)
- func (app *App) ServeHTTP(wr http.ResponseWriter, req *http.Request)
- func (app *App) ShowRoutes()
- func (app *App) TestCtx(req ...*http.Request) *Ctx
- func (app *App) UrlFor(name string, external bool, args ...string) string
- type Config
- type Cors
- type Ctx
- type File
- type Func
- type Header
- type JWT
- type MapCtrl
- type MatchInfo
- type Meth
- type Middleware
- 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) Websocket(headers http.Header) (*websocket.Conn, error)
- func (r *Request) WithContext(ctx context.Context) *Request
- type Response
- func (r *Response) BadRequest()
- func (r *Response) Close()
- func (r *Response) Created()
- func (r *Response) Forbidden()
- func (r *Response) HTML(body any, code int)
- func (r Response) Header() http.Header
- func (r *Response) ImATaerpot()
- func (r *Response) InternalServerError()
- func (r *Response) JSON(body any, code int)
- func (r *Response) MethodNotAllowed()
- func (r *Response) NoContent()
- func (r *Response) NotFound()
- func (r *Response) Ok()
- func (r *Response) RawResponse() http.ResponseWriter
- func (r *Response) Redirect(url string)
- func (r *Response) RenderTemplate(tmpl string, data ...any)
- func (r *Response) SetCookie(cookie *http.Cookie)
- func (r *Response) TEXT(body any, code int)
- func (r *Response) Unauthorized()
- func (r Response) Write(b []byte) (int, error)
- func (r Response) WriteHeader(statusCode int)
- type 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) Add(url, name string, f Func, meths []string)
- func (r *Router) AddRoute(route *Route)
- func (r *Router) AddRoutes(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)
Break execution, cleans up the response body, and writes the StatusCode to the response
func GetFullPath ¶
func GetFullPath() string
func MountSchemaFromRequest ¶
Types ¶
type App ¶
type App struct { *Router *Config // TODO -> add testConfig, ProdConfig AfterRequest, BeforeRequest, TearDownRequest Func // exec after each request, after send to cleint ( this dont has effect in response) // contains filtered or unexported fields }
func (*App) Build ¶
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() }
type Config ¶
type Config struct { Env string // environmnt SecretKey string // for sign session Servername string // for build url routes and route match ListeningInTLS bool // UrlFor return a URl with schema in "https:" TemplateFolder string // for render Templates Html. Default "templates/" TemplateFuncs template.FuncMap StaticFolder string // for serve static files StaticUrlPath string // url uf request static file EnableStatic bool // enable static endpoint for serving static files Silent bool // don't print logs LogFile string // save log info in file SessionExpires time.Duration SessionPermanentExpires time.Duration }
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 Ctx struct { // Clone Current App App *App Global map[string]any Request *Request // Current Request Response *Response // Current Response // Current Cookie Session Session *Session // New Schema valid from route schema Schema any SchemaFielder *c3po.Fielder // Contains information about the current request, route, etc... MatchInfo *MatchInfo // contains filtered or unexported fields }
type Header ¶
func (*Header) Save ¶
func (h *Header) Save(w http.ResponseWriter)
Write the headers in the response
type Middleware ¶
type Middleware Func
type Middlewares ¶
type Middlewares []Func
type Request ¶
type Request struct { Header Header Body *bytes.Buffer Method, RemoteAddr, RequestURI, ContentType string ContentLength int URL *url.URL Form map[string]any Args map[string]string Mime map[string]string Query url.Values 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 ¶
func (r *Request) Cancel()
Abort the current request. Server does not respond to client
func (*Request) ProtoAtLeast ¶
func (*Request) RawRequest ¶
func (*Request) UrlFor ¶
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 { *bytes.Buffer StatusCode int Headers Header // contains filtered or unexported fields }
func NewResponse ¶
func NewResponse(wr http.ResponseWriter, ctx *Ctx) *Response
func (*Response) BadRequest ¶
func (r *Response) BadRequest()
func (*Response) Close ¶
func (r *Response) Close()
Halts execution and closes the "response". This does not clear the response body
func (*Response) ImATaerpot ¶
func (r *Response) ImATaerpot()
func (*Response) InternalServerError ¶
func (r *Response) InternalServerError()
func (*Response) MethodNotAllowed ¶
func (r *Response) MethodNotAllowed()
func (*Response) RawResponse ¶
func (r *Response) RawResponse() http.ResponseWriter
func (*Response) RenderTemplate ¶
func (*Response) Unauthorized ¶
func (r *Response) Unauthorized()
func (Response) WriteHeader ¶
type Route ¶
type Router ¶
Click to show internal directories.
Click to hide internal directories.