mirror of
https://gitea.com/gitea/act_runner.git
synced 2025-06-12 17:47:14 +02:00
chore(runner): support update log and task
Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>
This commit is contained in:
@ -1,36 +1,58 @@
|
||||
package client
|
||||
|
||||
import "github.com/bufbuild/connect-go"
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/bufbuild/connect-go"
|
||||
)
|
||||
|
||||
type config struct {
|
||||
httpClient *http.Client
|
||||
skipVerify bool
|
||||
opts []connect.ClientOption
|
||||
}
|
||||
|
||||
// An Option configures a mutex.
|
||||
type Option interface {
|
||||
Apply(*HTTPClient)
|
||||
apply(*config)
|
||||
}
|
||||
|
||||
// OptionFunc is a function that configure a value.
|
||||
type OptionFunc func(*HTTPClient)
|
||||
type OptionFunc func(*config)
|
||||
|
||||
// Apply calls f(option)
|
||||
func (f OptionFunc) Apply(cli *HTTPClient) {
|
||||
f(cli)
|
||||
func (f OptionFunc) apply(cfg *config) {
|
||||
f(cfg)
|
||||
}
|
||||
|
||||
func WithSkipVerify(c bool) Option {
|
||||
return OptionFunc(func(cfg *config) {
|
||||
cfg.skipVerify = c
|
||||
})
|
||||
}
|
||||
|
||||
func WithClientOptions(opts ...connect.ClientOption) Option {
|
||||
return OptionFunc(func(cfg *config) {
|
||||
cfg.opts = append(cfg.opts, opts...)
|
||||
})
|
||||
}
|
||||
|
||||
// WithGRPC configures clients to use the HTTP/2 gRPC protocol.
|
||||
func WithGRPC(c bool) Option {
|
||||
return OptionFunc(func(cli *HTTPClient) {
|
||||
return OptionFunc(func(cfg *config) {
|
||||
if !c {
|
||||
return
|
||||
}
|
||||
cli.opts = append(cli.opts, connect.WithGRPC())
|
||||
cfg.opts = append(cfg.opts, connect.WithGRPC())
|
||||
})
|
||||
}
|
||||
|
||||
// WithGRPCWeb configures clients to use the gRPC-Web protocol.
|
||||
func WithGRPCWeb(c bool) Option {
|
||||
return OptionFunc(func(cli *HTTPClient) {
|
||||
return OptionFunc(func(cfg *config) {
|
||||
if !c {
|
||||
return
|
||||
}
|
||||
cli.opts = append(cli.opts, connect.WithGRPCWeb())
|
||||
cfg.opts = append(cfg.opts, connect.WithGRPCWeb())
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user