Skip to content

Commit

Permalink
Add workspace-aware NewHTTPPoolWithWorkspace.
Browse files Browse the repository at this point in the history
  • Loading branch information
udhos committed Dec 28, 2023
1 parent 0cfc57a commit 45c03a7
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,24 @@ type HTTPPoolOptions struct {
Context func(*http.Request) context.Context
}

// NewHTTPPool initializes an HTTP pool of peers, and registers itself as a PeerPicker.
// NewHTTPPoolWithWorkspace initializes an HTTP pool of peers, and registers itself as a PeerPicker.
// For convenience, it also registers itself as an http.Handler with http.DefaultServeMux.
// The self argument should be a valid base URL that points to the current server,
// for example "http://example.net:8000".
func NewHTTPPool(self string) *HTTPPool {
p := NewHTTPPoolOpts(self, nil)
func NewHTTPPoolWithWorkspace(ws *workspace, self string) *HTTPPool {
p := NewHTTPPoolOptsWithWorkspace(ws, self, nil)
http.Handle(p.opts.BasePath, p)
return p
}

// NewHTTPPool initializes an HTTP pool of peers, and registers itself as a PeerPicker.
// For convenience, it also registers itself as an http.Handler with http.DefaultServeMux.
// The self argument should be a valid base URL that points to the current server,
// for example "http://example.net:8000".
func NewHTTPPool(self string) *HTTPPool {
return NewHTTPPoolWithWorkspace(DefaultWorkspace, self)
}

// NewHTTPPoolOptsWithWorkspace initializes an HTTP pool of peers with the given options.
// Unlike NewHTTPPool, this function does not register the created pool as an HTTP handler.
// The returned *HTTPPool implements http.Handler and must be registered using http.Handle.
Expand Down

0 comments on commit 45c03a7

Please sign in to comment.