feat: swagger switch.
This commit is contained in:
@@ -20,3 +20,5 @@ mqtt:
|
|||||||
qos: 0
|
qos: 0
|
||||||
enable_measurement_subscriptions: false
|
enable_measurement_subscriptions: false
|
||||||
enable_training_event_subscription: true
|
enable_training_event_subscription: true
|
||||||
|
swagger:
|
||||||
|
enabled: true
|
||||||
|
|||||||
@@ -44,6 +44,11 @@ type AppConfig struct {
|
|||||||
DB DBConfig `mapstructure:"database" yaml:"database"`
|
DB DBConfig `mapstructure:"database" yaml:"database"`
|
||||||
AI AIConfig `mapstructure:"ai" yaml:"ai"`
|
AI AIConfig `mapstructure:"ai" yaml:"ai"`
|
||||||
MQTT MQTTConfig `mapstructure:"mqtt" yaml:"mqtt"`
|
MQTT MQTTConfig `mapstructure:"mqtt" yaml:"mqtt"`
|
||||||
|
Swagger SwaggerConfig `mapstructure:"swagger" yaml:"swagger"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SwaggerConfig struct {
|
||||||
|
Enabled bool `mapstructure:"enabled" yaml:"enabled"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitConfig() {
|
func InitConfig() {
|
||||||
|
|||||||
+4
-5
@@ -4,6 +4,7 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
swaggerFiles "github.com/swaggo/files"
|
swaggerFiles "github.com/swaggo/files"
|
||||||
ginSwagger "github.com/swaggo/gin-swagger"
|
ginSwagger "github.com/swaggo/gin-swagger"
|
||||||
|
"hr_receiver/config"
|
||||||
"hr_receiver/controllers"
|
"hr_receiver/controllers"
|
||||||
_ "hr_receiver/docs"
|
_ "hr_receiver/docs"
|
||||||
"hr_receiver/middleware"
|
"hr_receiver/middleware"
|
||||||
@@ -49,12 +50,12 @@ func SetupRouter() *gin.Engine {
|
|||||||
|
|
||||||
r.GET("/auth/token", deviceTokenHandler)
|
r.GET("/auth/token", deviceTokenHandler)
|
||||||
|
|
||||||
// Swagger API文档 (swaggo/gin-swagger,持久化鉴权信息)
|
// 开发模式下注册 API 文档路由
|
||||||
|
if config.App.Swagger.Enabled {
|
||||||
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler,
|
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler,
|
||||||
ginSwagger.PersistAuthorization(true),
|
ginSwagger.PersistAuthorization(true),
|
||||||
))
|
))
|
||||||
|
|
||||||
// Scalar 精美API文档
|
|
||||||
r.GET("/scalar", func(c *gin.Context) {
|
r.GET("/scalar", func(c *gin.Context) {
|
||||||
c.Header("Content-Type", "text/html; charset=utf-8")
|
c.Header("Content-Type", "text/html; charset=utf-8")
|
||||||
c.String(http.StatusOK, `<!doctype html>
|
c.String(http.StatusOK, `<!doctype html>
|
||||||
@@ -72,15 +73,13 @@ func SetupRouter() *gin.Engine {
|
|||||||
<script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script>
|
<script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script>
|
||||||
<script>
|
<script>
|
||||||
Scalar.createApiReference('#app', {
|
Scalar.createApiReference('#app', {
|
||||||
spec: {
|
|
||||||
url: '/swagger/doc.json',
|
url: '/swagger/doc.json',
|
||||||
},
|
|
||||||
persistAuth: true,
|
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>`)
|
</html>`)
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
v1 := r.Group("/api/v1")
|
v1 := r.Group("/api/v1")
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user