Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
ubogdan committed Nov 2, 2021
1 parent bd6de7c commit 3aa2141
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions swagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import (

// Config stores ginSwagger configuration variables.
type Config struct {
//The url pointing to API definition (normally swagger.json or swagger.yaml). Default is `doc.json`.
InstanceName string
// The url pointing to API definition (normally swagger.json or swagger.yaml). Default is `doc.json`.
URL string
DeepLinking bool
DocExpansion string
Expand Down Expand Up @@ -70,11 +71,6 @@ func WrapHandler(h *webdav.Handler, confs ...func(c *Config)) gin.HandlerFunc {

// CustomWrapHandler wraps `http.Handler` into `gin.HandlerFunc`
func CustomWrapHandler(config *Config, handler *webdav.Handler) gin.HandlerFunc {
return WrapHandlerName(swag.Name, config, handler)
}

// WrapHandlerName wraps `http.Handler` into `gin.HandlerFunc`.
func WrapHandlerName(name string, config *Config, handler *webdav.Handler) gin.HandlerFunc {
var once sync.Once

// create a template with name
Expand All @@ -83,6 +79,11 @@ func WrapHandlerName(name string, config *Config, handler *webdav.Handler) gin.H

var rexp = regexp.MustCompile(`(.*)(index\.html|doc\.json|favicon-16x16\.png|favicon-32x32\.png|/oauth2-redirect\.html|swagger-ui\.css|swagger-ui\.css\.map|swagger-ui\.js|swagger-ui\.js\.map|swagger-ui-bundle\.js|swagger-ui-bundle\.js\.map|swagger-ui-standalone-preset\.js|swagger-ui-standalone-preset\.js\.map)[\?|.]*`)

name := swag.Name
if len(config.InstanceName) > 0 {
name = config.InstanceName
}

return func(c *gin.Context) {
matches := rexp.FindStringSubmatch(c.Request.RequestURI)

Expand Down

0 comments on commit 3aa2141

Please sign in to comment.