Documentation ¶
Index ¶
- Variables
- func Daemon(apps ...*App) error
- func MountSchemaFromRequest(f *c3po.Fielder, rq *Request) (any, error)
- func TypeOf(obj any) string
- type App
- func (app *App) Build(addr ...string)
- func (app *App) ErrorHandler(statusCode int, f Func)
- func (app *App) Listen(host ...string) (err error)
- func (app *App) ListenTLS(certFile, certKey string, host ...string) (err error)
- func (app *App) Mount(routers ...*Router)
- func (app *App) ServeHTTP(wr http.ResponseWriter, req *http.Request)
- func (app *App) UrlFor(name string, external bool, args ...string) string
- type Config
- type Cors
- type Ctx
- type File
- type Func
- type Header
- type MapCtrl
- type MatchInfo
- type Meth
- type Request
- func (r *Request) BasicAuth() (username, password string, ok bool)
- func (r *Request) Clone(ctx context.Context) *Request
- func (r *Request) Context() context.Context
- func (r *Request) Ctx() *Ctx
- func (r *Request) ParseForm()
- 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() (*websocket.Conn, error)
- func (r *Request) WithContext(ctx context.Context) *Request
- type Response
- func (r *Response) Abort(code int)
- func (r *Response) BadRequest()
- func (r *Response) CheckErr(err error)
- 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) Hijack() (net.Conn, *bufio.ReadWriter, error)
- 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) Redirect(url string)
- func (r *Response) RenderTemplate(tmpl string, data ...any)
- func (r *Response) ServeFile(pathToFile string)
- 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(routes ...*Route)
- func (r *Router) AllMethods(url string, f Func)
- 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 MountSchemaFromRequest ¶
Types ¶
type App ¶
type App struct { *Router *Config BasicAuth func(*Ctx) (user string, pass string, ok bool) // custom func to parse Authorization Header AfterRequest, BeforeRequest, TearDownRequest Func // exec after each request, after send to cleint ( this dont has effect in response) Srv *http.Server // contains filtered or unexported fields }
func (*App) Build ¶
Build the App, but not start serve
example:
func index(ctx braza.Ctx){} // it's work func main() { app := braza.NewApp() app.GET("/",index) app.Build(":5000") app.UrlFor("index",true) } // it's don't work func main() { app := braza.NewApp() app.GET("/",index) app.UrlFor("index",true) }
func (*App) ErrorHandler ¶
func (*App) Mount ¶
Register Router in app
func main() { api := braza.NewRouter("api") api.post("/products") api.get("/products/{productID:int}") app := braza.NewApp(nil) app.Mount(api) // do anything ... app.Listen() }
type Config ¶
type Config struct { Env string // environmnt (default 'development') SecretKey string // for sign session (default ”) Servername string // for build url routes and route match (default ”) ListeningInTLS bool // UrlFor return a URl with schema in "https:" (default 'false') TemplateFolder string // for render Templates Html. Default "templates/" TemplateFuncs template.FuncMap DisableParseFormBody bool // Disable default parse of Request.Form -> if true, use Request.ParseForm() DisableTemplateReloader bool // if app in dev mode, disable template's reload (default false) StaticFolder string // for serve static files (default '/assets') StaticUrlPath string // url uf request static file (default '/assets') DisableStatic bool // disable static endpoint for serving static files (default false) Silent bool // don't print logs (default false) LogFile string // save log info in file (default ”) DotenvFileName string DisableFileWatcher bool // disable autoreload in dev mode (default false) SessionExpires time.Duration // (default 30 minutes) SessionPermanentExpires time.Duration // (default 31 days) SessionPublicKey *rsa.PublicKey SessionPrivateKey *rsa.PrivateKey // contains filtered or unexported fields }
func NewConfig ¶
func NewConfig() *Config
Usage:
env := "dev" devConfig := braza.NewConfig() prodConfig := braza.NewConfig() var cfg *Config if env == "dev"{ cfg = devConfig } else { cfg = prodConfig } app := braza.NewApp(cfg) ...
func (*Config) SetupFromFile ¶
setup config from json, yalm
type Cors ¶
type Cors struct { MaxAge string // Access-Control-Max-Age AllowOrigins []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 // contains filtered or unexported fields }
If present on route or router, allows resource sharing between origins
type Ctx ¶
type Ctx struct { App *App // Clone Current App Global map[string]any // global variables of current request Session *Session // Current Cookie Session *Response // Current Response Request *Request // Current Request // New Schema valid from route schema Schema Schema 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 Request ¶
type Request struct { Header Header Body *bytes.Buffer Method, RemoteAddr, RequestURI, ContentType string ContentLength int URL *url.URL Host string Port string 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) 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 *braza.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) ImATaerpot ¶
func (r *Response) ImATaerpot()
func (*Response) InternalServerError ¶
func (r *Response) InternalServerError()
func (*Response) MethodNotAllowed ¶
func (r *Response) MethodNotAllowed()
func (*Response) RenderTemplate ¶
func (*Response) Unauthorized ¶
func (r *Response) Unauthorized()
func (Response) WriteHeader ¶
type Route ¶
type Router ¶
type Router struct { Cors *Cors Name string Routes []*Route Prefix string Subdomain string WsUpgrader *websocket.Upgrader Middlewares []Func StrictSlash bool // contains filtered or unexported fields }
func (*Router) AllMethods ¶
type Schema ¶
type Schema any
example:
type User struct{ Name string `braza:"name=name"` Email string `braza:"name=username,in=auth"` // name need be 'username' Password string `braza:"name=password,in=auth"` // name need be 'password' ProfilePhoto *braza.File `braza:"name=img,in=files"` KeepConnected bool `braza:"name=keep,inquery"` } func AnyHandler(ctx *braza.Ctx){ u, ok := ctx.Schema.(*User) ... }
Source Files ¶
Click to show internal directories.
Click to hide internal directories.