From 784be7a030e07e053aaedff79cb1e278f4b9021e Mon Sep 17 00:00:00 2001 From: Sediman Date: Wed, 27 May 2026 07:34:35 +0200 Subject: [PATCH] docs: document panic conditions in Handle, StaticFS, and Bind --- routergroup.go | 5 +++++ utils.go | 3 +++ 2 files changed, 8 insertions(+) diff --git a/routergroup.go b/routergroup.go index c01b917e..60010969 100644 --- a/routergroup.go +++ b/routergroup.go @@ -100,6 +100,9 @@ func (group *RouterGroup) handle(httpMethod, relativePath string, handlers Handl // 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 // communication with a proxy). +// +// Handle panics if httpMethod is not a valid, uppercase HTTP method name +// (ASCII letters only, e.g. "GET", "POST"). func (group *RouterGroup) Handle(httpMethod, relativePath string, handlers ...HandlerFunc) IRoutes { if matched := regEnLetter.MatchString(httpMethod); !matched { panic("http method " + httpMethod + " is not valid") @@ -200,6 +203,8 @@ func (group *RouterGroup) Static(relativePath, root string) IRoutes { // StaticFS works just like `Static()` but a custom `http.FileSystem` can be used instead. // Gin by default uses: gin.Dir() +// +// StaticFS panics if relativePath contains URL parameters (:param or *param). func (group *RouterGroup) StaticFS(relativePath string, fs http.FileSystem) IRoutes { if strings.Contains(relativePath, ":") || strings.Contains(relativePath, "*") { panic("URL parameters can not be used when serving a static folder") diff --git a/utils.go b/utils.go index 2fecce46..055aebd6 100644 --- a/utils.go +++ b/utils.go @@ -26,6 +26,9 @@ const localhostIP = "127.0.0.1" const localhostIPv6 = "::1" // Bind is a helper function for given interface object and returns a Gin middleware. +// +// Bind panics if val is a pointer; pass the struct value directly +// (e.g., Bind(MyStruct{}) instead of Bind(&MyStruct{})). func Bind(val any) HandlerFunc { value := reflect.ValueOf(val) if value.Kind() == reflect.Ptr {