Open
Description
Hi there,
Could we make a pull request to add an essential part which is missing on instantiating a client from the Goa generated code:
The client takes the following signature:
func NewClient(
scheme string,
host string,
doer goahttp.Doer,
enc func(*http.Request) goahttp.Encoder,
dec func(*http.Response) goahttp.Decoder,
restoreBody bool,
) *Client
which leaves no room to set the base url like schema: https
, baseURL: domain.com/a/b/c
and all endpoints will start with https://domain.com/a/b/c/....
. The host
parameter cannot be misused as its used in url.URL{...}
which has different semantics.
We would like to add another non-breaking function NewClientWithOpts(opts ... ClientOption)
which lets us chose
all relevant options, and defaulting the ones not set.
NewClientWithOpts(
WithSchema("https"),
WithHost("domain.com:8080"),
WithURL(url.Parse("https://domain.com/a/b/c?a=asdf), // here only taking host and schema and path.
WithDoer(...),
WithDecoder(...),
WithEncoder(...),
WithRestoreBody(true))
etc.
The old function NewClient
can then forward to
NewClientsWithOpts(WithBaseURL(url.URL{Scheme: scheme, Host: host}))
.
We really need this somewhat soon.
Implementation
type Client struct {
...
scheme string
host string
basePath string // this is probably enough to add (prefix with `/` if not given)
encoder func(*http.Request) goahttp.Encoder
decoder func(*http.Response) goahttp.Decoder
}
Metadata
Metadata
Assignees
Labels
No labels