yats.git

commit 36d56ef4702983ceef8ac16de5efdf7dee78844e

Author: Paolo Lulli <paolo@lulli.net>

Swap away swagger boilerplate

 server/rest/rest-metric.go | 2 +-
 server/service-rest.go | 8 ++------
 server/swagger.go | 22 ++++++++++++++++++++++


diff --git a/server/rest/rest-metric.go b/server/rest/rest-metric.go
index 2a054e91629cb06e13c89cdc9e1e6620acb10dbb..2c7b96f5280c8972934ab08ee1436d961e879153 100644
--- a/server/rest/rest-metric.go
+++ b/server/rest/rest-metric.go
@@ -19,7 +19,7 @@ 	"yats-server/db"
 	"yats-server/model"
 )
 
-// @BasePath /api/v1
+// @BasePath /
 
 // WriteMetric godoc
 // @Summary write metric to db




diff --git a/server/service-rest.go b/server/service-rest.go
index a8ebb0ef764c297899c2b837b1de549c630d26ce..23764963b84f37817c981e170425c05f4eabba87 100644
--- a/server/service-rest.go
+++ b/server/service-rest.go
@@ -15,10 +15,6 @@ 	"yats-server/config"
 	"yats-server/rest"
 
 	"github.com/gin-gonic/gin"
-
-	swaggerfiles "github.com/swaggo/files"
-	ginSwagger "github.com/swaggo/gin-swagger"
-	"yats-server/docs"
 )
 
 func RestService(c config.Configuration) {
@@ -27,7 +23,7 @@ 	//	session = DB
 	address := c.RestAddress
 
 	router := gin.Default()
-	docs.SwaggerInfo.BasePath = "/api/v1"
+
 	router.Use(CorsHeaders())
 
 	router.SetTrustedProxies([]string{"127.0.0.1"})
@@ -39,7 +35,7 @@
 	router.POST("/event", rest.WriteEvent)
 	router.POST("/event/get", rest.GetEvents)
 
-	router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))
+	enableSwaggerEndpoint(router)
 
 	router.Run(address)
 	//router.RunTLS(address, c.CertFile, c.KeyFile)




diff --git a/server/swagger.go b/server/swagger.go
new file mode 100644
index 0000000000000000000000000000000000000000..f915a44c76df99d0cd19be345c36cfd8420c1506
--- /dev/null
+++ b/server/swagger.go
@@ -0,0 +1,22 @@
+/**
+ * Yats - yats
+ *
+ * This file is licensed under the Affero General Public License version 3 or
+ * later. See the COPYING file.
+ *
+ * @author Paolo Lulli <kevwe.com>
+ * @copyright Paolo Lulli 2024
+ */
+package main
+
+import (
+	"github.com/gin-gonic/gin"
+	swaggerfiles "github.com/swaggo/files"
+	ginSwagger "github.com/swaggo/gin-swagger"
+	"yats-server/docs"
+)
+
+func enableSwaggerEndpoint(router *gin.Engine) {
+	docs.SwaggerInfo.BasePath = "/"
+	router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))
+}