Documentation
¶
Index ¶
- Constants
- Variables
- func Log(message string)
- type BagoetteClient
- func (b *BagoetteClient) Close() error
- func (b *BagoetteClient) GetHTTPHandler() *http.ServeMux
- func (b *BagoetteClient) GetRoutes() []Route
- func (b *BagoetteClient) MaxUploadSize(size int64) (*BagoetteClient, error)
- func (b *BagoetteClient) NewRouter() *RouteGroup
- func (b *BagoetteClient) Port(port int) *BagoetteClient
- func (b *BagoetteClient) Serve() error
- func (b *BagoetteClient) ServeAppearance()
- func (b *BagoetteClient) SetAllowCredentials(allowCredentials bool) *BagoetteClient
- func (b *BagoetteClient) SetAllowedHeaders(headers []string) *BagoetteClient
- func (b *BagoetteClient) SetAllowedMethods(methods []string) *BagoetteClient
- func (b *BagoetteClient) SetAllowedOrigins(origins []string) *BagoetteClient
- func (b *BagoetteClient) SetExposedHeaders(headers []string) *BagoetteClient
- func (b *BagoetteClient) SetMaxAge(maxAge int) *BagoetteClient
- func (b *BagoetteClient) SetOptions(opts Options) *BagoetteClient
- func (b *BagoetteClient) ShowRoutes()
- type Cors
- type Ctx
- func (c *Ctx) Abort() error
- func (c *Ctx) Bind(body any) error
- func (c *Ctx) Check() error
- func (c *Ctx) DownloadFile(path string) error
- func (c *Ctx) Error(status int, message string) error
- func (c *Ctx) Get(key string) (any, error)
- func (c *Ctx) GetAndSaveFiles(key string, path string) error
- func (c *Ctx) GetFiles(key string) ([]*multipart.FileHeader, error)
- func (c *Ctx) Header(key string) (string, error)
- func (c *Ctx) Next() error
- func (c *Ctx) Param(key string) (string, error)
- func (c *Ctx) Query(key string) (string, error)
- func (c *Ctx) Reset() error
- func (c *Ctx) Respond(status int, data any) error
- func (c *Ctx) RespondFile(path string) error
- func (c *Ctx) SaveFile(file *multipart.FileHeader, path string) error
- func (c *Ctx) Set(key string, value any) error
- func (c *Ctx) SetHeader(key string, value string) error
- type HandlerFunc
- type Options
- type Route
- type RouteGroup
- func (r *RouteGroup) AddNewRouteToBagoetteClient(route *Route) error
- func (r *RouteGroup) Connect(path string, handlers ...HandlerFunc) error
- func (r *RouteGroup) Delete(path string, handlers ...HandlerFunc) error
- func (r *RouteGroup) Get(path string, handlers ...HandlerFunc) error
- func (r *RouteGroup) Group(prefix string) *RouteGroup
- func (r *RouteGroup) Head(path string, handlers ...HandlerFunc) error
- func (r *RouteGroup) NewRoute(method string, path string, handlers []HandlerFunc) error
- func (r *RouteGroup) Options(path string, handlers ...HandlerFunc) error
- func (r *RouteGroup) Patch(path string, handlers ...HandlerFunc) error
- func (r *RouteGroup) Post(path string, handlers ...HandlerFunc) error
- func (r *RouteGroup) Put(path string, handlers ...HandlerFunc) error
- func (r *RouteGroup) Trace(path string, handlers ...HandlerFunc) error
- func (r *RouteGroup) Use(handlers ...HandlerFunc) *RouteGroup
Constants ¶
const ( Reset = "\033[0m" Red = "\033[31m" Green = "\033[32m" Yellow = "\033[33m" Blue = "\033[34m" White = "\033[37m" )
Variables ¶
Functions ¶
Types ¶
type BagoetteClient ¶
type BagoetteClient struct {
Opts *Options
Routes *[]Route
// contains filtered or unexported fields
}
Bagoette main struct: work as the core of the library and provide all the features like router, middleware, context, etc
func (*BagoetteClient) Close ¶
func (b *BagoetteClient) Close() error
func (*BagoetteClient) GetHTTPHandler ¶
func (b *BagoetteClient) GetHTTPHandler() *http.ServeMux
func (*BagoetteClient) GetRoutes ¶
func (b *BagoetteClient) GetRoutes() []Route
func (*BagoetteClient) MaxUploadSize ¶ added in v0.4.0
func (b *BagoetteClient) MaxUploadSize(size int64) (*BagoetteClient, error)
MaxUploadSize: set the max upload size of the server
func (*BagoetteClient) NewRouter ¶
func (b *BagoetteClient) NewRouter() *RouteGroup
func (*BagoetteClient) Port ¶
func (b *BagoetteClient) Port(port int) *BagoetteClient
Port: set the port of the server
func (*BagoetteClient) Serve ¶
func (b *BagoetteClient) Serve() error
func (*BagoetteClient) ServeAppearance ¶
func (b *BagoetteClient) ServeAppearance()
func (*BagoetteClient) SetAllowCredentials ¶ added in v0.5.2
func (b *BagoetteClient) SetAllowCredentials(allowCredentials bool) *BagoetteClient
func (*BagoetteClient) SetAllowedHeaders ¶ added in v0.5.2
func (b *BagoetteClient) SetAllowedHeaders(headers []string) *BagoetteClient
func (*BagoetteClient) SetAllowedMethods ¶ added in v0.5.2
func (b *BagoetteClient) SetAllowedMethods(methods []string) *BagoetteClient
func (*BagoetteClient) SetAllowedOrigins ¶ added in v0.5.2
func (b *BagoetteClient) SetAllowedOrigins(origins []string) *BagoetteClient
func (*BagoetteClient) SetExposedHeaders ¶ added in v0.5.2
func (b *BagoetteClient) SetExposedHeaders(headers []string) *BagoetteClient
func (*BagoetteClient) SetMaxAge ¶ added in v0.5.2
func (b *BagoetteClient) SetMaxAge(maxAge int) *BagoetteClient
func (*BagoetteClient) SetOptions ¶ added in v0.5.1
func (b *BagoetteClient) SetOptions(opts Options) *BagoetteClient
func (*BagoetteClient) ShowRoutes ¶
func (b *BagoetteClient) ShowRoutes()
type Cors ¶ added in v0.5.0
type Ctx ¶
type Ctx struct {
Writer http.ResponseWriter
Request *http.Request
Data map[string]any
// contains filtered or unexported fields
}
Context struct: work as the container of the request and response
func NewContext ¶
func (*Ctx) DownloadFile ¶ added in v0.4.2
DownloadFile: Download a file
func (*Ctx) GetAndSaveFiles ¶ added in v0.4.2
GetAndSaveFiles: get files from the request and save them by calling Getfiles and then save them directly using SaveFile example: c.GetAndSaveFiles("myFiles", "/path/to/save") will get files with key "myFiles" and save them to "/path/to/save"
func (*Ctx) GetFiles ¶ added in v0.4.2
func (c *Ctx) GetFiles(key string) ([]*multipart.FileHeader, error)
GetFiles: get files from the request example: c.GetFiles("myFiles") will return files with key "myFiles"
func (*Ctx) Header ¶
Header: get a header example: c.Header("Content-Type") will return "application/json"
func (*Ctx) Next ¶
Next: call the next handler and reset the context after the last handler is called
func (*Ctx) Param ¶
Param: get a path parameter example: /users/:id c.Param("id") will return the id of the user
func (*Ctx) Query ¶
Query: get a query parameter by the key of query example: /users?name=john&age=20 c.Query("name") will return "john" c.Query("age") will return "20"
func (*Ctx) RespondFile ¶ added in v0.4.2
RespondFile: Respond with a file
func (*Ctx) SaveFile ¶ added in v0.4.1
func (c *Ctx) SaveFile(file *multipart.FileHeader, path string) error
SaveFile: save a file example: c.SaveFile(file, "/path/to/save") will save the file to the given path
type HandlerFunc ¶
type HandlerFunc func(c *Ctx)
HandlerFunc type: Define the handler function that use bagoette context
type Options ¶ added in v0.4.0
func NewOptions ¶ added in v0.4.0
func NewOptions() *Options
type Route ¶
type Route struct {
// contains filtered or unexported fields
}
Route struct: Define individual route
type RouteGroup ¶ added in v0.4.0
type RouteGroup struct {
Middlewares []HandlerFunc
Prefix string
// contains filtered or unexported fields
}
Router struct: work as the router of the server
func (*RouteGroup) AddNewRouteToBagoetteClient ¶ added in v0.4.0
func (r *RouteGroup) AddNewRouteToBagoetteClient(route *Route) error
func (*RouteGroup) Connect ¶ added in v0.4.0
func (r *RouteGroup) Connect(path string, handlers ...HandlerFunc) error
func (*RouteGroup) Delete ¶ added in v0.4.0
func (r *RouteGroup) Delete(path string, handlers ...HandlerFunc) error
func (*RouteGroup) Get ¶ added in v0.4.0
func (r *RouteGroup) Get(path string, handlers ...HandlerFunc) error
func (*RouteGroup) Group ¶ added in v0.4.0
func (r *RouteGroup) Group(prefix string) *RouteGroup
func (*RouteGroup) Head ¶ added in v0.4.0
func (r *RouteGroup) Head(path string, handlers ...HandlerFunc) error
func (*RouteGroup) NewRoute ¶ added in v0.4.0
func (r *RouteGroup) NewRoute(method string, path string, handlers []HandlerFunc) error
func (*RouteGroup) Options ¶ added in v0.4.0
func (r *RouteGroup) Options(path string, handlers ...HandlerFunc) error
func (*RouteGroup) Patch ¶ added in v0.4.0
func (r *RouteGroup) Patch(path string, handlers ...HandlerFunc) error
func (*RouteGroup) Post ¶ added in v0.4.0
func (r *RouteGroup) Post(path string, handlers ...HandlerFunc) error
func (*RouteGroup) Put ¶ added in v0.4.0
func (r *RouteGroup) Put(path string, handlers ...HandlerFunc) error
func (*RouteGroup) Trace ¶ added in v0.4.0
func (r *RouteGroup) Trace(path string, handlers ...HandlerFunc) error
func (*RouteGroup) Use ¶ added in v0.4.0
func (r *RouteGroup) Use(handlers ...HandlerFunc) *RouteGroup