Documentation ¶
Index ¶
- func SetOutput(w io.Writer)
- type HandlerFunc
- type Middleware
- type Request
- func (r *Request) Abort()
- func (r *Request) BINARY(code int, data []byte)
- func (r *Request) Cookie(key string) (*http.Cookie, error)
- func (r *Request) Cookies() []*http.Cookie
- func (r *Request) ERROR(code int, err error)
- func (r *Request) FILE(code int, fileName string)
- func (r *Request) GetStatus() int
- func (r *Request) HTML(code int, name string, data any)
- func (r *Request) HTMLTemplate(code int, templateName string, tmpl *template.Template, data any)
- func (r *Request) IsAborted() bool
- func (r *Request) JSON(code int, data any)
- func (r *Request) PostFormVal(key string) string
- func (r *Request) PostFormValues() url.Values
- func (r *Request) QueryValue(key string) string
- func (r *Request) QueryValues() url.Values
- func (r *Request) Redirect(code int, url string)
- func (r *Request) RemoveAllCookies()
- func (r *Request) RemoveAllCookiesExcept(exceptions ...string)
- func (r *Request) RemoveCookie(key string)
- func (r *Request) SetCookie(key string, val string, exp time.Time)
- func (r *Request) SetCookieObj(cookie *http.Cookie)
- func (r *Request) SetCookiePath(path string)
- func (r *Request) SetCookieWithOptions(key, val string, exp time.Time)
- func (r *Request) SetCookiesHTTPOnly(httpOnly bool)
- func (r *Request) SetCookiesSameSite(same http.SameSite)
- func (r *Request) SetCookiesSecure(secure bool)
- func (r *Request) SetDefaultCookieOptions(options *http.Cookie)
- func (r *Request) SetSecureFlagAutomatically()
- func (r *Request) SetStatus(code int)
- func (r *Request) SetValue(key string, val any)
- func (r *Request) Value(key string) any
- func (r *Request) Values() map[string]any
- func (r *Request) XML(code int, data any)
- func (r *Request) XMLIndent(code int, data any, prefix, indent string)
- type Router
- func (r *Router) CONNECT(path string, handler HandlerFunc)
- func (r *Router) DELETE(path string, handler HandlerFunc)
- func (r *Router) GET(path string, handler HandlerFunc)
- func (r *Router) GroupMiddleware(method, path string, middleware ...Middleware)
- func (r *Router) HEAD(path string, handler HandlerFunc)
- func (r *Router) Middleware(method, path string, middleware ...Middleware)
- func (r *Router) OPTIONS(path string, handler HandlerFunc)
- func (r *Router) PATCH(path string, handler HandlerFunc)
- func (r *Router) POST(path string, handler HandlerFunc)
- func (r *Router) PUT(path string, handler HandlerFunc)
- func (r *Router) Run(addr string)
- func (r *Router) RunWithTLS(addr, certFile, keyFile string)
- func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (r *Router) TRACE(path string, handler HandlerFunc)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type HandlerFunc ¶
type HandlerFunc func(*Request)
HandlerFunc is a function that can be registered to a router to handle HTTP requests.
type Middleware ¶
type Middleware func(HandlerFunc) HandlerFunc
type Request ¶
type Request struct { Writer http.ResponseWriter Req *http.Request // contains filtered or unexported fields }
Request is a struct for handlers, to interact with request.
func (*Request) HTML ¶
HTML parses data to HTML format and sends a response with the provided code. If there is no file with such name, it will abort with a 500 error status code.
func (*Request) HTMLTemplate ¶
HTMLTemplate same as HTML, but you can put your html template to execute. You need to set template name to template.Template struct. And then pass it to this function.
Example:
tmpl, err := template.ParseFiles("main.html", "footer.html") if err != nil { // handle err } r.HTMLTemplate(200,"main.html", tmpl, data)
If there is no file with such name, will abort with 500 error status code.
func (*Request) PostFormVal ¶
PostFormVal returns value from post form.
func (*Request) PostFormValues ¶
PostFormValues returns all values from post form.
func (*Request) QueryValue ¶
QueryValue returns value from query.
func (*Request) QueryValues ¶
QueryValues returns all values from query.
func (*Request) Redirect ¶
Redirect redirects request to another url. Only codes from 300 to 308 are valid.
func (*Request) RemoveAllCookies ¶
func (r *Request) RemoveAllCookies()
RemoveAllCookies removes all cookies from request.
func (*Request) RemoveAllCookiesExcept ¶
RemoveAllCookiesExcept removes all cookies from the response except the specified ones.
func (*Request) RemoveCookie ¶
RemoveCookie removes cookie by key.
func (*Request) SetCookieObj ¶
SetCookieObj puts cookie object to cookies.
func (*Request) SetCookiePath ¶
SetCookiePath sets the path for the cookie.
func (*Request) SetCookieWithOptions ¶
SetCookieWithOptions puts a key-value pair into the cookies with additional options.
func (*Request) SetCookiesHTTPOnly ¶
SetCookiesHTTPOnly sets httpOnly to all cookies.
func (*Request) SetCookiesSameSite ¶
SetCookiesSameSite sets sameSite to all cookies.
func (*Request) SetCookiesSecure ¶
SetCookiesSecure sets secure to all cookies.
func (*Request) SetDefaultCookieOptions ¶
SetDefaultCookieOptions sets default values for cookie attributes.
func (*Request) SetSecureFlagAutomatically ¶
func (r *Request) SetSecureFlagAutomatically()
SetSecureFlagAutomatically sets the Secure flag based on the request's scheme.
func (*Request) SetStatus ¶
SetStatus should be used,if you don't use response functions of this package.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
func NewRouter ¶
func NewRouter() *Router
NewRouter returns a new router instance with default configuration.
func (*Router) CONNECT ¶
func (r *Router) CONNECT(path string, handler HandlerFunc)
func (*Router) DELETE ¶
func (r *Router) DELETE(path string, handler HandlerFunc)
func (*Router) GET ¶
func (r *Router) GET(path string, handler HandlerFunc)
func (*Router) GroupMiddleware ¶
func (r *Router) GroupMiddleware(method, path string, middleware ...Middleware)
GroupMiddleware adds middleware to the group of routes that have the same path prefix Example:
router := NewRouter() router.GroupMiddleware(http.MethodGet, "/api", middleware1, middleware2) router.GET("/api/users", usersHandler) router.GET("/api/users/:id", userHandler) // The middleware1 and middleware2 will be applied to both usersHandler and userHandler
func (*Router) HEAD ¶
func (r *Router) HEAD(path string, handler HandlerFunc)
func (*Router) Middleware ¶
func (r *Router) Middleware(method, path string, middleware ...Middleware)
Middleware adds middleware to the route with the specified path Example:
router := NewRouter() router.Middleware(http.MethodGet, "/api/users", middleware1, middleware2) router.GET("/api/users", usersHandler)
The middleware1 and middleware2 will be applied to usersHandler
func (*Router) OPTIONS ¶
func (r *Router) OPTIONS(path string, handler HandlerFunc)
func (*Router) PATCH ¶
func (r *Router) PATCH(path string, handler HandlerFunc)
func (*Router) POST ¶
func (r *Router) POST(path string, handler HandlerFunc)
func (*Router) PUT ¶
func (r *Router) PUT(path string, handler HandlerFunc)
func (*Router) RunWithTLS ¶
RunWithTLS starts the HTTPS server.
func (*Router) TRACE ¶
func (r *Router) TRACE(path string, handler HandlerFunc)