Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions arpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions mounter.go
Original file line number Diff line number Diff line change
@@ -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)
}