Initial commit

This commit is contained in:
2019-02-03 20:56:58 +01:00
commit 2a8a20195a
30 changed files with 1595 additions and 0 deletions

16
chi/mount.go Normal file
View File

@ -0,0 +1,16 @@
package chi
import (
peering "forge.cadoles.com/wpetit/go-http-peering"
"forge.cadoles.com/wpetit/go-http-peering/server"
"github.com/go-chi/chi"
)
func Mount(r chi.Router, store peering.Store, funcs ...server.OptionFunc) {
r.Post(peering.AdvertisePath, server.AdvertiseHandler(store, funcs...))
r.Group(func(r chi.Router) {
r.Use(server.Authenticate(store, funcs...))
r.Post(peering.UpdatePath, server.UpdateHandler(store, funcs...))
r.Post(peering.PingPath, server.PingHandler(store, funcs...))
})
}

35
chi/mount_test.go Normal file
View File

@ -0,0 +1,35 @@
package chi
import (
"testing"
peering "forge.cadoles.com/wpetit/go-http-peering"
"forge.cadoles.com/wpetit/go-http-peering/memory"
"github.com/go-chi/chi"
)
func TestMount(t *testing.T) {
r := chi.NewRouter()
store := memory.NewStore()
Mount(r, store)
routes := r.Routes()
if g, e := len(routes), 3; g != e {
t.Errorf("len(r.Routes()): got '%v', expected '%v'", g, e)
}
if g, e := routes[0].Pattern, peering.AdvertisePath; g != e {
t.Errorf("routes[0].Pattern: got '%v', expected '%v'", g, e)
}
if g, e := routes[1].Pattern, peering.PingPath; g != e {
t.Errorf("routes[1].Pattern: got '%v', expected '%v'", g, e)
}
if g, e := routes[2].Pattern, peering.UpdatePath; g != e {
t.Errorf("routes[2].Pattern: got '%v', expected '%v'", g, e)
}
}