add graphviz dot download endpoint
This commit is contained in:
parent
8b93868983
commit
f05829d0c8
|
@ -327,6 +327,9 @@ func (db *DB) All() []*tree {
|
|||
})
|
||||
return ret
|
||||
}
|
||||
func (db *DB) Dot() string {
|
||||
return db.provisions.Dot()
|
||||
}
|
||||
func (db *DB) Alloc(bits int) (*tree, error) {
|
||||
db.Lock()
|
||||
defer db.Unlock()
|
||||
|
@ -407,7 +410,7 @@ func prefixShape(p netip.Prefix) Rect {
|
|||
return Rect{
|
||||
Y: 0,
|
||||
X: 0,
|
||||
H: 1 << (bits / 2),
|
||||
H: 1 << (bits / 2), // TODO: handle overflow for normal ipv6 subnet sizes :)
|
||||
W: 1 << ((bits + 1) / 2),
|
||||
}
|
||||
}
|
||||
|
|
10
main.go
10
main.go
|
@ -4,6 +4,7 @@ import (
|
|||
"embed"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/netip"
|
||||
|
@ -30,6 +31,7 @@ func (s *server) setup() {
|
|||
|
||||
s.mux.HandleFunc("/api/used/", s.apiUsed)
|
||||
s.mux.HandleFunc("/api/print/", s.apiPrint)
|
||||
s.mux.HandleFunc("/api/treemap.dot", s.apiDot)
|
||||
//s.mux.HandleFunc("/api/provision/", s.apiProvision)
|
||||
|
||||
s.ipdb = ipalloc.NewDB("10.83.46.0/23", 32, 29, 28, 27, 26)
|
||||
|
@ -72,7 +74,13 @@ func (s *server) template(w http.ResponseWriter, r *http.Request) {
|
|||
Treemap: s.ipdb.Treemap(),
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
func (s *server) apiDot(w http.ResponseWriter, r *http.Request) {
|
||||
_, err := io.WriteString(w, s.ipdb.Dot())
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue