whatismyip/router/setup.go

38 lines
915 B
Go
Raw Normal View History

2021-11-10 19:06:12 +00:00
package router
import (
"html/template"
"log"
"github.com/dcarrillo/whatismyip/internal/setting"
2025-01-02 19:13:41 +00:00
"github.com/dcarrillo/whatismyip/service"
2021-11-10 19:06:12 +00:00
"github.com/gin-gonic/gin"
)
2025-01-02 19:13:41 +00:00
var geoSvc *service.Geo
2021-11-10 19:06:12 +00:00
func SetupTemplate(r *gin.Engine) {
if setting.App.TemplatePath == "" {
t, _ := template.New("home").Parse(home)
r.SetHTMLTemplate(t)
} else {
log.Printf("Template %s has been loaded", setting.App.TemplatePath)
r.LoadHTMLFiles(setting.App.TemplatePath)
}
}
2025-01-02 19:13:41 +00:00
func Setup(r *gin.Engine, geo *service.Geo) {
geoSvc = geo
2021-11-10 19:06:12 +00:00
r.GET("/", getRoot)
r.GET("/scan/tcp/:port", scanTCPPort)
2021-11-10 19:06:12 +00:00
r.GET("/client-port", getClientPortAsString)
r.GET("/geo", getGeoAsString)
r.GET("/geo/:field", getGeoAsString)
r.GET("/asn", getASNAsString)
r.GET("/asn/:field", getASNAsString)
r.GET("/headers", getHeadersAsSortedString)
r.GET("/all", getAllAsString)
r.GET("/json", getJSON)
r.GET("/:header", getHeaderAsString)
}