Documentation ¶
Overview ¶
* This file contains all the functions and structs that are used to add modules to the framework.
- In this file are all the models and functions for testing.
Index ¶
- Constants
- Variables
- func Delete(path string, action routeFunction) *routeModel
- func Get(path string, action routeFunction) *routeModel
- func GetKeyFromYAML(key string) interface{}
- func Group(prefix string, action func()) *groupModel
- func InitModules(m ...initModuleFunc)
- func LoadConfigFIle(file string)
- func Post(path string, action routeFunction) *routeModel
- func Put(path string, action routeFunction) *routeModel
- func Route(r string, data SMap) string
- func Set404NotFound(function routeFunction)
- func SetGlobalMiddlewares(function ...middlewareFunction)
- func SetMethodNotAllowed(function routeFunction)
- func SetPanicHandler(function panicHandler)
- type Context
- func (c *Context) Bytes(s int, b []byte)
- func (c *Context) ContentType(content string)
- func (c *Context) GetHeader(key string) string
- func (c *Context) Json(s int, j interface{}) error
- func (c *Context) NewForm() (Form, error)
- func (c *Context) NewMultiPartFormDataForm(maxMemory int64) (MultipartFormData, error)
- func (c *Context) Param(key string) string
- func (c *Context) Params() map[string]string
- func (c *Context) Query(key string) string
- func (c *Context) RawJson(j interface{})
- func (c *Context) Redirect(url string, code int)
- func (c *Context) RedirectToRoute(name string, params SMap, code int)
- func (c *Context) RemoteAddr() (ip string, port int)
- func (c *Context) Session(session string) (Session, error)
- func (c *Context) SetFormValues(ptr interface{}, formValues map[string]interface{})
- func (c *Context) SetHeader(key string, value string)
- func (c *Context) Status(s int) *Context
- func (c *Context) Text(statusCode int, s string)
- func (c *Context) Textf(statusCode int, format string, a ...interface{})
- type Form
- type FormFile
- type Map
- type MultipartFormData
- type OnError
- type SMap
- type Session
- func (s *Session) Delete(key string)
- func (s *Session) Domain(domain string)
- func (s *Session) Expire()
- func (s *Session) Get(key string) interface{}
- func (s *Session) GetFlash(key string) interface{}
- func (s *Session) IsNew() bool
- func (s *Session) MaxAge(age int)
- func (s *Session) Path(path string)
- func (s *Session) SameSite(sameSite http.SameSite)
- func (s *Session) Secure(secure bool)
- func (s *Session) Set(key string, value interface{})
- func (s *Session) SetFlash(key string, value interface{})
- type Test
- func (t *Test) FromTestingKey(key string) testingValue
- func (t *Test) NewMultiPartFormData(httpMethod string, url string) multiPartFormDataForTesting
- func (t *Test) NewTestingForm(httpMethod string, to string) (*formForTesting, error)
- func (t *Test) TestRoute(route string) bool
- func (t *Test) UrlOk(url string) bool
Constants ¶
const ( ContinueRequest = 0 StopRequest = 1 )
ContinueRequest and StopRequest are aliases in every sense of 0 and 1, used to indicate whether to continue or stop a request.
Variables ¶
var ( // Store is the session store. Store *sessions.CookieStore )
Functions ¶
func GetKeyFromYAML ¶
func GetKeyFromYAML(key string) interface{}
GetKeyFromYAML returns the value of the key from the YAML config file.
If the key is empty, it returns the whole YAML config file as a map.
func InitModules ¶
func InitModules(m ...initModuleFunc)
InitModules will add the modules to the framework.
func LoadConfigFIle ¶
func LoadConfigFIle(file string)
LoadConfigFile reads the .yaml file and starts the web server based on its configuration.
func Set404NotFound ¶
func Set404NotFound(function routeFunction)
Sets a "404 url not found" function.
func SetGlobalMiddlewares ¶
func SetGlobalMiddlewares(function ...middlewareFunction)
Sets global middlewares.
func SetMethodNotAllowed ¶
func SetMethodNotAllowed(function routeFunction)
Sets a general "method not allowed" function.
func SetPanicHandler ¶
func SetPanicHandler(function panicHandler)
Sets a general "handle panic" function.
Types ¶
type Context ¶
type Context struct { ResponseWriter http.ResponseWriter Request *http.Request // // SharedPayload gets cleaned up after each request. SharedPayload map[string]interface{} // Buf is a buffer that is used to store the response body. Buf *bytes.Buffer // Headers stores the response headers. Headers map[string]string // contains filtered or unexported fields }
func (*Context) ContentType ¶
ContentType sets the Content-Type header.
func (*Context) NewForm ¶
NewForm creates a new "Form" model for HTTP requests with "application/x-www-form-urlencoded".
func (*Context) NewMultiPartFormDataForm ¶
func (c *Context) NewMultiPartFormDataForm(maxMemory int64) (MultipartFormData, error)
Creates a new "MultipartFormData" model for HTTP requests with "multipart/form-data".
For a detailed explanation of the value of the "maxMemory" variable see https://pkg.go.dev/net/http#Request.ParseMultipartForm.
func (*Context) RedirectToRoute ¶
RedirectToRoute redirects the user to a specific route.
Route is called internally to get the route.
func (*Context) RemoteAddr ¶
RemoteAddr returns the address of the client.
func (*Context) Session ¶
Session always returns a session, even if empty.
The session will not be saved if no changes are made.
func (*Context) SetFormValues ¶
SetFormValues sets the values of the struct from a map by the "form" tag.
type Form ¶
type Form struct {
// contains filtered or unexported fields
}
type MultipartFormData ¶
type MultipartFormData struct {
// contains filtered or unexported fields
}
func (*MultipartFormData) Get ¶
func (f *MultipartFormData) Get(value string) string
Gets the first value associated with the given key except files.
func (*MultipartFormData) GetAll ¶
func (f *MultipartFormData) GetAll() interface{}
Gets all POST data of the form except files
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
type Test ¶
type Test struct {
// contains filtered or unexported fields
}
Main struct for testing.
func LoadConfigFileForTests ¶
LoadConfigFileForTests returns a test model for testing.
func (*Test) FromTestingKey ¶
FromTestingKey returns the value inside the "key" inside the "testing" key of the .yaml file as a testingValue struct.
func (*Test) NewMultiPartFormData ¶
NewMultiPartFormDataForm returns a new multiPartFormDataForTesting for making requests of type multipart/form-data.
func (*Test) NewTestingForm ¶
NewTestingForm returns a new formForTesting for making requests of type application/x-www-form-urlencoded.
func (*Test) TestRoute ¶
TestRoute makes an HTTP GET request to the route URL (if it exists) and checks if the response status code is 200.
The request will make it to the path http://127.0.0.1:port/path. So the server must be running locally.