57 lines
963 B
Go
57 lines
963 B
Go
package client
|
|
|
|
import (
|
|
"crypto/rsa"
|
|
"net/http"
|
|
|
|
peering "forge.cadoles.com/wpetit/go-http-peering"
|
|
)
|
|
|
|
type Options struct {
|
|
PeerID peering.PeerID
|
|
HTTPClient *http.Client
|
|
BaseURL string
|
|
PrivateKey *rsa.PrivateKey
|
|
}
|
|
|
|
type OptionFunc func(*Options)
|
|
|
|
func WithPeerID(id peering.PeerID) OptionFunc {
|
|
return func(opts *Options) {
|
|
opts.PeerID = id
|
|
}
|
|
}
|
|
|
|
func WithPrivateKey(pk *rsa.PrivateKey) OptionFunc {
|
|
return func(opts *Options) {
|
|
opts.PrivateKey = pk
|
|
}
|
|
}
|
|
|
|
func WithHTTPClient(client *http.Client) OptionFunc {
|
|
return func(opts *Options) {
|
|
opts.HTTPClient = client
|
|
}
|
|
}
|
|
|
|
func WithBaseURL(url string) OptionFunc {
|
|
return func(opts *Options) {
|
|
opts.BaseURL = url
|
|
}
|
|
}
|
|
|
|
func defaultOptions() *Options {
|
|
return &Options{
|
|
HTTPClient: http.DefaultClient,
|
|
PeerID: peering.NewPeerID(),
|
|
}
|
|
}
|
|
|
|
func createOptions(funcs ...OptionFunc) *Options {
|
|
options := defaultOptions()
|
|
for _, fn := range funcs {
|
|
fn(options)
|
|
}
|
|
return options
|
|
}
|