diff --git a/arpc.go b/arpc.go index a4e6c32..450a41b 100644 --- a/arpc.go +++ b/arpc.go @@ -45,6 +45,10 @@ type Validatable interface { Valid() error } +type Mux interface { + Handle(pattern string, handler http.Handler) +} + type Manager struct { Decoder Decoder Encoder Encoder @@ -357,6 +361,14 @@ func (m *Manager) Handler(f any) http.Handler { }) } +func (m *Manager) Mount(mux Mux, pattern string, f any) { + mux.Handle(pattern, m.Handler(f)) +} + +func (m *Manager) Mounter(mux Mux) *Mounter { + return &Mounter{Manager: m, Mux: mux} +} + type MiddlewareContext struct { r *http.Request w http.ResponseWriter diff --git a/mounter.go b/mounter.go new file mode 100644 index 0000000..0734559 --- /dev/null +++ b/mounter.go @@ -0,0 +1,11 @@ +package arpc + +type Mounter struct { + Manager *Manager + Mux Mux +} + +// Mount mounts the handler to the mux +func (m *Mounter) Mount(pattern string, f any) { + m.Manager.Mount(m.Mux, pattern, f) +}