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
|
return ret
|
||||||
}
|
}
|
||||||
|
func (db *DB) Dot() string {
|
||||||
|
return db.provisions.Dot()
|
||||||
|
}
|
||||||
func (db *DB) Alloc(bits int) (*tree, error) {
|
func (db *DB) Alloc(bits int) (*tree, error) {
|
||||||
db.Lock()
|
db.Lock()
|
||||||
defer db.Unlock()
|
defer db.Unlock()
|
||||||
|
@ -407,7 +410,7 @@ func prefixShape(p netip.Prefix) Rect {
|
||||||
return Rect{
|
return Rect{
|
||||||
Y: 0,
|
Y: 0,
|
||||||
X: 0,
|
X: 0,
|
||||||
H: 1 << (bits / 2),
|
H: 1 << (bits / 2), // TODO: handle overflow for normal ipv6 subnet sizes :)
|
||||||
W: 1 << ((bits + 1) / 2),
|
W: 1 << ((bits + 1) / 2),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
10
main.go
10
main.go
|
@ -4,6 +4,7 @@ import (
|
||||||
"embed"
|
"embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
|
@ -30,6 +31,7 @@ func (s *server) setup() {
|
||||||
|
|
||||||
s.mux.HandleFunc("/api/used/", s.apiUsed)
|
s.mux.HandleFunc("/api/used/", s.apiUsed)
|
||||||
s.mux.HandleFunc("/api/print/", s.apiPrint)
|
s.mux.HandleFunc("/api/print/", s.apiPrint)
|
||||||
|
s.mux.HandleFunc("/api/treemap.dot", s.apiDot)
|
||||||
//s.mux.HandleFunc("/api/provision/", s.apiProvision)
|
//s.mux.HandleFunc("/api/provision/", s.apiProvision)
|
||||||
|
|
||||||
s.ipdb = ipalloc.NewDB("10.83.46.0/23", 32, 29, 28, 27, 26)
|
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(),
|
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 {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue