Enabled the authorization middleware

This commit is contained in:
2025-09-21 14:21:04 +01:00
parent 3821c3fffc
commit 2c92ee61a0
2 changed files with 10 additions and 10 deletions
+5
View File
@@ -0,0 +1,5 @@
# CertifiedInvSWDB
Small API to serve the currently existing certified invoicing softwares in
Portugal.
With it there's a small CLI to help scraping new data to populate the DB.
+5 -10
View File
@@ -1,10 +1,8 @@
// Package api will server the SW data via a JSON REST API. // Package api will server the SW data via a JSON REST API.
package api package api
// TODO: configure the logging
import ( import (
"net/http" "net/http"
// _ "net/http/pprof"
"strconv" "strconv"
sw "github.com/ESilva15/PTInvCertSWDB/sw" sw "github.com/ESilva15/PTInvCertSWDB/sw"
@@ -46,22 +44,19 @@ func get(c *gin.Context) {
func count(c *gin.Context) { func count(c *gin.Context) {
count := sw.Count() count := sw.Count()
c.JSON(http.StatusOK, gin.H{"count": count}) c.JSON(http.StatusOK, gin.H{"count": count})
} }
func RunServer() error { func RunServer() error {
// go func() {
// http.ListenAndServe("localhost:6060", nil)
// }()
gin.SetMode(ginMode) gin.SetMode(ginMode)
router := gin.Default() router := gin.Default()
authGroup := router.Group("/") authGroup := router.Group("/")
// authGroup.Use(APIAuthMiddleWare()) authGroup.Use(APIAuthMiddleWare())
authGroup.GET("/sw/:id", get) {
authGroup.GET("/count", count) authGroup.GET("/sw/:id", get)
authGroup.GET("/count", count)
}
// Star the SW service // Star the SW service
err := sw.StartSWService(sw.FILEDB) err := sw.StartSWService(sw.FILEDB)