Initial commit: web_hghl_server
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package swaggerutil
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"videoweb/pub/common/netutil"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
swaggerFiles "github.com/swaggo/files"
|
||||
ginSwagger "github.com/swaggo/gin-swagger"
|
||||
)
|
||||
|
||||
func isDevHost(runMode string, svcListenIp string) bool {
|
||||
localIp := netutil.GetLocalIP()
|
||||
return (runMode == "dev" || runMode == "debug") && localIp != svcListenIp
|
||||
}
|
||||
|
||||
func SetupGinSwagger(runMode, svcListenIp, svcListenPort string) func(r *gin.Engine) {
|
||||
return func(r *gin.Engine) {
|
||||
if isDevHost(runMode, svcListenIp) {
|
||||
url := ginSwagger.URL(fmt.Sprintf("http://%s:%s/swagger/doc.json", netutil.GetLocalIP(), svcListenPort))
|
||||
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler, url))
|
||||
} else {
|
||||
url := ginSwagger.URL(fmt.Sprintf("http://%s:%s/swagger/doc.json", svcListenIp, svcListenPort))
|
||||
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler, url))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user