powerdns-remote-http-example/addr-map-api.go

56 lines
832 B
Go
Raw Permalink Normal View History

2024-09-14 09:12:10 +03:00
package main
import (
"net/http"
"sync"
"github.com/gin-gonic/gin"
)
func setupAddrMapApi(r *gin.Engine) {
// TODO
r.GET("/addrmap", func(c *gin.Context) {
var wg sync.WaitGroup
m4 := make([]AddrMap, 0)
m6 := make([]AddrMap, 0)
wg.Add(1)
go func() {
defer wg.Done()
addr4.Range(func(key, value any) bool {
a, ok := value.(AddrMap)
if !ok {
// early return
return true
}
a.Ttl = uint32(a.GetTtl())
m4 = append(m4, a)
return true
})
}()
wg.Add(1)
go func() {
defer wg.Done()
addr6.Range(func(key, value any) bool {
a, ok := value.(AddrMap)
if !ok {
// early return
return true
}
a.Ttl = uint32(a.GetTtl())
m6 = append(m6, a)
return true
})
}()
wg.Wait()
m4 = append(m4, m6...)
c.JSON(http.StatusOK, m4)
})
}