mirror of
https://github.com/fiatjaf/khatru.git
synced 2025-11-23 04:28:11 +01:00
nip-86: add generic handler.
This commit is contained in:
9
nip86.go
9
nip86.go
@@ -37,6 +37,7 @@ type RelayManagementAPI struct {
|
|||||||
BlockIP func(ctx context.Context, ip net.IP, reason string) error
|
BlockIP func(ctx context.Context, ip net.IP, reason string) error
|
||||||
UnblockIP func(ctx context.Context, ip net.IP, reason string) error
|
UnblockIP func(ctx context.Context, ip net.IP, reason string) error
|
||||||
ListBlockedIPs func(ctx context.Context) ([]nip86.IPReason, error)
|
ListBlockedIPs func(ctx context.Context) ([]nip86.IPReason, error)
|
||||||
|
Generic func(ctx context.Context, request nip86.Request) (nip86.Response, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rl *Relay) HandleNIP86(w http.ResponseWriter, r *http.Request) {
|
func (rl *Relay) HandleNIP86(w http.ResponseWriter, r *http.Request) {
|
||||||
@@ -267,7 +268,13 @@ func (rl *Relay) HandleNIP86(w http.ResponseWriter, r *http.Request) {
|
|||||||
resp.Result = result
|
resp.Result = result
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
resp.Error = fmt.Sprintf("method '%s' not known", mp.MethodName())
|
if rl.ManagementAPI.Generic == nil {
|
||||||
|
resp.Error = fmt.Sprintf("method '%s' not known", mp.MethodName())
|
||||||
|
} else if result, err := rl.ManagementAPI.Generic(ctx, req); err != nil {
|
||||||
|
resp.Error = err.Error()
|
||||||
|
} else {
|
||||||
|
resp.Result = result
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user