mirror of
https://github.com/ProtonMail/go-proton-api.git
synced 2025-12-23 23:57:50 -05:00
51 lines
760 B
Go
51 lines
760 B
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
"net/url"
|
|
)
|
|
|
|
type Call struct {
|
|
URL *url.URL
|
|
Method string
|
|
Status int
|
|
|
|
RequestHeader http.Header
|
|
RequestBody []byte
|
|
|
|
ResponseHeader http.Header
|
|
ResponseBody []byte
|
|
}
|
|
|
|
type callWatcher struct {
|
|
paths map[string]struct{}
|
|
callFn func(Call)
|
|
}
|
|
|
|
func newCallWatcher(fn func(Call), paths ...string) callWatcher {
|
|
pathMap := make(map[string]struct{}, len(paths))
|
|
|
|
for _, path := range paths {
|
|
pathMap[path] = struct{}{}
|
|
}
|
|
|
|
return callWatcher{
|
|
paths: pathMap,
|
|
callFn: fn,
|
|
}
|
|
}
|
|
|
|
func (watcher *callWatcher) isWatching(path string) bool {
|
|
if len(watcher.paths) == 0 {
|
|
return true
|
|
}
|
|
|
|
_, ok := watcher.paths[path]
|
|
|
|
return ok
|
|
}
|
|
|
|
func (watcher *callWatcher) publish(call Call) {
|
|
watcher.callFn(call)
|
|
}
|