refactor: dependency injection instead of package globals (#57)

* refactor: export Settings type, Setup returns value

* refactor: resolver.Setup takes explicit Settings struct

* refactor: GetHeadersWithoutTrustedHeaders takes explicit header params

* refactor: server constructors take narrow config

* refactor: Router struct with handler methods, remove geoSvc global

* refactor: wire DI through main, remove setting.App references

* refactor: remove App global, use returned Settings

* refactor: update router tests for DI

* chore: fix lint issues — rename ServerTimeouts to Timeouts, fix shadowed variables
This commit is contained in:
2026-07-21 18:37:21 +02:00
committed by GitHub
parent 3874f6af3f
commit 2e32a20f60
19 changed files with 298 additions and 253 deletions
+6 -6
View File
@@ -81,13 +81,13 @@ var asnOutput = map[string]asnDataFormatter{
},
}
func getGeoAsString(ctx *gin.Context) {
if geoSvc == nil {
func (rt *Router) getGeoAsString(ctx *gin.Context) {
if rt.geo == nil {
ctx.String(http.StatusNotFound, http.StatusText(http.StatusNotFound))
return
}
record := geoSvc.LookUpCity(net.ParseIP(ctx.ClientIP()))
record := rt.geo.LookUpCity(net.ParseIP(ctx.ClientIP()))
if record == nil {
ctx.String(http.StatusNotFound, http.StatusText(http.StatusNotFound))
return
@@ -107,13 +107,13 @@ func getGeoAsString(ctx *gin.Context) {
ctx.String(http.StatusOK, g.format(record))
}
func getASNAsString(ctx *gin.Context) {
if geoSvc == nil {
func (rt *Router) getASNAsString(ctx *gin.Context) {
if rt.geo == nil {
ctx.String(http.StatusNotFound, http.StatusText(http.StatusNotFound))
return
}
record := geoSvc.LookUpASN(net.ParseIP(ctx.ClientIP()))
record := rt.geo.LookUpASN(net.ParseIP(ctx.ClientIP()))
if record == nil {
ctx.String(http.StatusNotFound, http.StatusText(http.StatusNotFound))
return