mirror of
https://github.com/gin-gonic/gin.git
synced 2026-06-06 03:08:11 +08:00
docs: document panic conditions in Handle, StaticFS, and Bind
This commit is contained in:
parent
5f4f964325
commit
02678bf430
@ -100,6 +100,8 @@ func (group *RouterGroup) handle(httpMethod, relativePath string, handlers Handl
|
|||||||
// This function is intended for bulk loading and to allow the usage of less
|
// This function is intended for bulk loading and to allow the usage of less
|
||||||
// frequently used, non-standardized or custom methods (e.g. for internal
|
// frequently used, non-standardized or custom methods (e.g. for internal
|
||||||
// communication with a proxy).
|
// communication with a proxy).
|
||||||
|
//
|
||||||
|
// Handle panics if httpMethod is not a valid HTTP method (uppercase ASCII letters only).
|
||||||
func (group *RouterGroup) Handle(httpMethod, relativePath string, handlers ...HandlerFunc) IRoutes {
|
func (group *RouterGroup) Handle(httpMethod, relativePath string, handlers ...HandlerFunc) IRoutes {
|
||||||
if matched := regEnLetter.MatchString(httpMethod); !matched {
|
if matched := regEnLetter.MatchString(httpMethod); !matched {
|
||||||
panic("http method " + httpMethod + " is not valid")
|
panic("http method " + httpMethod + " is not valid")
|
||||||
@ -200,6 +202,8 @@ func (group *RouterGroup) Static(relativePath, root string) IRoutes {
|
|||||||
|
|
||||||
// StaticFS works just like `Static()` but a custom `http.FileSystem` can be used instead.
|
// StaticFS works just like `Static()` but a custom `http.FileSystem` can be used instead.
|
||||||
// Gin by default uses: gin.Dir()
|
// Gin by default uses: gin.Dir()
|
||||||
|
//
|
||||||
|
// StaticFS panics if relativePath contains URL parameters (: or *).
|
||||||
func (group *RouterGroup) StaticFS(relativePath string, fs http.FileSystem) IRoutes {
|
func (group *RouterGroup) StaticFS(relativePath string, fs http.FileSystem) IRoutes {
|
||||||
if strings.Contains(relativePath, ":") || strings.Contains(relativePath, "*") {
|
if strings.Contains(relativePath, ":") || strings.Contains(relativePath, "*") {
|
||||||
panic("URL parameters can not be used when serving a static folder")
|
panic("URL parameters can not be used when serving a static folder")
|
||||||
|
|||||||
1
utils.go
1
utils.go
@ -26,6 +26,7 @@ const localhostIP = "127.0.0.1"
|
|||||||
const localhostIPv6 = "::1"
|
const localhostIPv6 = "::1"
|
||||||
|
|
||||||
// Bind is a helper function for given interface object and returns a Gin middleware.
|
// Bind is a helper function for given interface object and returns a Gin middleware.
|
||||||
|
// It panics if val is a pointer; pass the struct value directly (e.g., Bind(Struct{}) not Bind(&Struct{})).
|
||||||
func Bind(val any) HandlerFunc {
|
func Bind(val any) HandlerFunc {
|
||||||
value := reflect.ValueOf(val)
|
value := reflect.ValueOf(val)
|
||||||
if value.Kind() == reflect.Ptr {
|
if value.Kind() == reflect.Ptr {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user