mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-07-27 17:28:35 +00:00
chore(client): support gRPC and gRPC web protocol
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
0b885c5e5f
commit
d359276fe1
5 changed files with 51 additions and 1 deletions
36
client/options.go
Normal file
36
client/options.go
Normal file
|
@ -0,0 +1,36 @@
|
|||
package client
|
||||
|
||||
import "github.com/bufbuild/connect-go"
|
||||
|
||||
// An Option configures a mutex.
|
||||
type Option interface {
|
||||
Apply(*HTTPClient)
|
||||
}
|
||||
|
||||
// OptionFunc is a function that configure a value.
|
||||
type OptionFunc func(*HTTPClient)
|
||||
|
||||
// Apply calls f(option)
|
||||
func (f OptionFunc) Apply(cli *HTTPClient) {
|
||||
f(cli)
|
||||
}
|
||||
|
||||
// WithGRPC configures clients to use the HTTP/2 gRPC protocol.
|
||||
func WithGRPC(c bool) Option {
|
||||
return OptionFunc(func(cli *HTTPClient) {
|
||||
if !c {
|
||||
return
|
||||
}
|
||||
cli.opts = append(cli.opts, connect.WithGRPC())
|
||||
})
|
||||
}
|
||||
|
||||
// WithGRPCWeb configures clients to use the gRPC-Web protocol.
|
||||
func WithGRPCWeb(c bool) Option {
|
||||
return OptionFunc(func(cli *HTTPClient) {
|
||||
if !c {
|
||||
return
|
||||
}
|
||||
cli.opts = append(cli.opts, connect.WithGRPCWeb())
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue