feat: add disabling handler (#33)
This commit is contained in:
committed by
Eason Lin
parent
6192cec7d2
commit
6f4fdc3ec4
+18
-1
@@ -1,10 +1,12 @@
|
||||
package ginSwagger
|
||||
|
||||
import (
|
||||
"golang.org/x/net/webdav"
|
||||
"html/template"
|
||||
"os"
|
||||
"regexp"
|
||||
|
||||
"golang.org/x/net/webdav"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/swaggo/swag"
|
||||
)
|
||||
@@ -49,6 +51,21 @@ func WrapHandler(h *webdav.Handler) gin.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// DisablingWrapHandler turn handler off
|
||||
// if specified environment variable passed
|
||||
func DisablingWrapHandler(h *webdav.Handler, envName string) gin.HandlerFunc {
|
||||
eFlag := os.Getenv(envName)
|
||||
if eFlag != "" {
|
||||
return func(c *gin.Context) {
|
||||
// Simulate behavior when route unspecified and
|
||||
// return 404 HTTP code
|
||||
c.String(404, "")
|
||||
}
|
||||
}
|
||||
|
||||
return WrapHandler(h)
|
||||
}
|
||||
|
||||
const swagger_index_templ = `<!-- HTML for static distribution bundle build -->
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
Reference in New Issue
Block a user