[Feature request] jrpc set hostname and path instead of the full URL #639
wiardvanrij
started this conversation in
General
Replies: 2 comments
-
This sounds a tiny bit more like a https://github.com/fortio/fortio/discussions than an issue but let's keep it here for now/now that it is here let's say you're making a client library for a server X that has
endpoints requiring a token I think you would do something like: type XCli struct {
BaseServer string
Token string
}
type Foo struct{} // replace with actual result from foo call
type Bar struct{} // replace with actual result from bar call
func (x *XCli) makeDest(path string) *jrpc.Destination {
return &jrpc.Destination{
Headers: &http.Header{
"Authorization": {"Bearer " + x.Token},
},
URL: x.BaseServer + path,
}
}
func (x *XCli) Foo() (*Foo, error) {
return jrpc.Get[Foo](x.makeDest("/foo"))
}
func (x *XCli) Bar() (*Bar, error) {
return jrpc.Get[Bar](x.makeDest("/bar"))
}
//... |
Beta Was this translation helpful? Give feedback.
0 replies
-
going to close this for now as I think |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
At the moment I'm doing something like this:
Which is useful as that sets the object which I then can re-use by setting just the URL. For example:
jrpcDest = getJrpcDest(fooToken)
followed by
It would be nice to allow to split URL into a host and a path function. This way I can improve my initial 'object' by including the host. Then on every usage, I can merely include the path instead of the full URL. This improves usability and allows you to set a single jrcp object that contains the needed header(s) and hostname.
Beta Was this translation helpful? Give feedback.
All reactions