feat: add disabling handler (#33)

This commit is contained in:
Nikita Goncharov
2018-09-26 05:28:12 +03:00
committed by Eason Lin
parent 6192cec7d2
commit 6f4fdc3ec4
3 changed files with 96 additions and 1 deletions
+18 -1
View File
@@ -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">