From b6bfa35f347c9d0a161b627db2735b20d521742e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Fran=C3=A7a=20de=20Oliveira?= Date: Fri, 6 Oct 2023 11:59:11 -0700 Subject: [PATCH 1/2] improvement: Unexport field of unexported and non-serialized struct --- .../httpclient/client_builder.go | 146 +++++++++--------- conjure-go-client/httpclient/client_params.go | 82 +++++----- .../httpclient/client_params_test.go | 4 +- conjure-go-client/httpclient/config.go | 2 +- .../httpclient/config_refreshable_test.go | 4 +- conjure-go-client/httpclient/trace.go | 12 +- 6 files changed, 125 insertions(+), 125 deletions(-) diff --git a/conjure-go-client/httpclient/client_builder.go b/conjure-go-client/httpclient/client_builder.go index a37f75ee..9e6856aa 100644 --- a/conjure-go-client/httpclient/client_builder.go +++ b/conjure-go-client/httpclient/client_builder.go @@ -47,34 +47,34 @@ const ( ) type clientBuilder struct { - HTTP *httpClientBuilder + http *httpClientBuilder - URIs refreshable.StringSlice - URIScorerBuilder func([]string) internal.URIScoringMiddleware + uris refreshable.StringSlice + uriScorerBuilder func([]string) internal.URIScoringMiddleware - ErrorDecoder ErrorDecoder + errorDecoder ErrorDecoder - BytesBufferPool bytesbuffers.Pool - MaxAttempts refreshable.IntPtr - RetryParams refreshingclient.RefreshableRetryParams + bytesBufferPool bytesbuffers.Pool + maxAttempts refreshable.IntPtr + retryParams refreshingclient.RefreshableRetryParams } type httpClientBuilder struct { - ServiceNameTag metrics.Tag // Service name is not refreshable. - Timeout refreshable.Duration - DialerParams refreshingclient.RefreshableDialerParams - TLSConfig *tls.Config // TODO: Make this refreshing and wire into transport - TransportParams refreshingclient.RefreshableTransportParams - Middlewares []Middleware + serviceNameTag metrics.Tag // Service name is not refreshable. + timeout refreshable.Duration + dialerParams refreshingclient.RefreshableDialerParams + tlsConfig *tls.Config // TODO: Make this refreshing and wire into transport + transportParams refreshingclient.RefreshableTransportParams + middlewares []Middleware - DisableMetrics refreshable.Bool - MetricsTagProviders []TagsProvider + disableMetrics refreshable.Bool + metricsTagProviders []TagsProvider // These middleware options are not refreshed anywhere because they are not in ClientConfig, // but they could be made refreshable if ever needed. - CreateRequestSpan bool - DisableRecovery bool - InjectTraceHeaders bool + createRequestSpan bool + disableRecovery bool + injectTraceHeaders bool } func (b *httpClientBuilder) Build(ctx context.Context, params ...HTTPClientParam) (RefreshableHTTPClient, error) { @@ -87,21 +87,21 @@ func (b *httpClientBuilder) Build(ctx context.Context, params ...HTTPClientParam } } transport := refreshingclient.NewRefreshableTransport(ctx, - b.TransportParams, - b.TLSConfig, - refreshingclient.NewRefreshableDialer(ctx, b.DialerParams)) - transport = wrapTransport(transport, newMetricsMiddleware(b.ServiceNameTag, b.MetricsTagProviders, b.DisableMetrics)) + b.transportParams, + b.tlsConfig, + refreshingclient.NewRefreshableDialer(ctx, b.dialerParams)) + transport = wrapTransport(transport, newMetricsMiddleware(b.serviceNameTag, b.metricsTagProviders, b.disableMetrics)) transport = wrapTransport(transport, traceMiddleware{ - ServiceName: b.ServiceNameTag.Value(), - CreateRequestSpan: b.CreateRequestSpan, - InjectHeaders: b.InjectTraceHeaders, + serviceName: b.serviceNameTag.Value(), + createRequestSpan: b.createRequestSpan, + injectHeaders: b.injectTraceHeaders, }) - if !b.DisableRecovery { + if !b.disableRecovery { transport = wrapTransport(transport, recoveryMiddleware{}) } - transport = wrapTransport(transport, b.Middlewares...) + transport = wrapTransport(transport, b.middlewares...) - return refreshingclient.NewRefreshableHTTPClient(transport, b.Timeout), nil + return refreshingclient.NewRefreshableHTTPClient(transport, b.timeout), nil } // NewClient returns a configured client ready for use. @@ -130,42 +130,42 @@ func newClient(ctx context.Context, b *clientBuilder, params ...ClientParam) (Cl return nil, err } } - if b.URIs == nil { - return nil, werror.Error("httpclient URLs must not be empty", werror.SafeParam("serviceName", b.HTTP.ServiceNameTag.Value())) + if b.uris == nil { + return nil, werror.Error("httpclient URLs must not be empty", werror.SafeParam("serviceName", b.http.serviceNameTag.Value())) } var edm Middleware - if b.ErrorDecoder != nil { - edm = errorDecoderMiddleware{errorDecoder: b.ErrorDecoder} + if b.errorDecoder != nil { + edm = errorDecoderMiddleware{errorDecoder: b.errorDecoder} } - middleware := b.HTTP.Middlewares - b.HTTP.Middlewares = nil + middleware := b.http.middlewares + b.http.middlewares = nil - httpClient, err := b.HTTP.Build(ctx) + httpClient, err := b.http.Build(ctx) if err != nil { return nil, err } var recovery Middleware - if !b.HTTP.DisableRecovery { + if !b.http.disableRecovery { recovery = recoveryMiddleware{} } - uriScorer := internal.NewRefreshableURIScoringMiddleware(b.URIs, func(uris []string) internal.URIScoringMiddleware { - if b.URIScorerBuilder == nil { + uriScorer := internal.NewRefreshableURIScoringMiddleware(b.uris, func(uris []string) internal.URIScoringMiddleware { + if b.uriScorerBuilder == nil { return internal.NewBalancedURIScoringMiddleware(uris, func() int64 { return time.Now().UnixNano() }) } - return b.URIScorerBuilder(uris) + return b.uriScorerBuilder(uris) }) return &clientImpl{ client: httpClient, uriScorer: uriScorer, - maxAttempts: b.MaxAttempts, - backoffOptions: b.RetryParams, + maxAttempts: b.maxAttempts, + backoffOptions: b.retryParams, middlewares: middleware, errorDecoderMiddleware: edm, recoveryMiddleware: recovery, - bufferPool: b.BytesBufferPool, + bufferPool: b.bytesBufferPool, }, nil } @@ -173,7 +173,7 @@ func newClient(ctx context.Context, b *clientBuilder, params ...ClientParam) (Cl // We apply "sane defaults" before applying the provided params. func NewHTTPClient(params ...HTTPClientParam) (*http.Client, error) { b := newClientBuilder() - provider, err := b.HTTP.Build(context.TODO(), params...) + provider, err := b.http.Build(context.TODO(), params...) if err != nil { return nil, err } @@ -190,22 +190,22 @@ func NewHTTPClientFromRefreshableConfig(ctx context.Context, config RefreshableC if err := newClientBuilderFromRefreshableConfig(ctx, config, b, nil, true); err != nil { return nil, err } - return b.HTTP.Build(ctx, params...) + return b.http.Build(ctx, params...) } func newClientBuilder() *clientBuilder { defaultTLSConfig, _ := tlsconfig.NewClientConfig() return &clientBuilder{ - HTTP: &httpClientBuilder{ - ServiceNameTag: metrics.Tag{}, - Timeout: refreshable.NewDuration(refreshable.NewDefaultRefreshable(defaultHTTPTimeout)), - DialerParams: refreshingclient.NewRefreshingDialerParams(refreshable.NewDefaultRefreshable(refreshingclient.DialerParams{ + http: &httpClientBuilder{ + serviceNameTag: metrics.Tag{}, + timeout: refreshable.NewDuration(refreshable.NewDefaultRefreshable(defaultHTTPTimeout)), + dialerParams: refreshingclient.NewRefreshingDialerParams(refreshable.NewDefaultRefreshable(refreshingclient.DialerParams{ DialTimeout: defaultDialTimeout, KeepAlive: defaultKeepAlive, SocksProxyURL: nil, })), - TLSConfig: defaultTLSConfig, - TransportParams: refreshingclient.NewRefreshingTransportParams(refreshable.NewDefaultRefreshable(refreshingclient.TransportParams{ + tlsConfig: defaultTLSConfig, + transportParams: refreshingclient.NewRefreshingTransportParams(refreshable.NewDefaultRefreshable(refreshingclient.TransportParams{ MaxIdleConns: defaultMaxIdleConns, MaxIdleConnsPerHost: defaultMaxIdleConnsPerHost, DisableHTTP2: false, @@ -219,18 +219,18 @@ func newClientBuilder() *clientBuilder { HTTP2ReadIdleTimeout: defaultHTTP2ReadIdleTimeout, HTTP2PingTimeout: defaultHTTP2PingTimeout, })), - DisableMetrics: refreshable.NewBool(refreshable.NewDefaultRefreshable(false)), - DisableRecovery: false, - CreateRequestSpan: true, - InjectTraceHeaders: true, - MetricsTagProviders: nil, - Middlewares: nil, + disableMetrics: refreshable.NewBool(refreshable.NewDefaultRefreshable(false)), + disableRecovery: false, + createRequestSpan: true, + injectTraceHeaders: true, + metricsTagProviders: nil, + middlewares: nil, }, - URIs: nil, - BytesBufferPool: nil, - ErrorDecoder: restErrorDecoder{}, - MaxAttempts: nil, - RetryParams: refreshingclient.NewRefreshingRetryParams(refreshable.NewDefaultRefreshable(refreshingclient.RetryParams{ + uris: nil, + bytesBufferPool: nil, + errorDecoder: restErrorDecoder{}, + maxAttempts: nil, + retryParams: refreshingclient.NewRefreshingRetryParams(refreshable.NewDefaultRefreshable(refreshingclient.RetryParams{ InitialBackoff: defaultInitialBackoff, MaxBackoff: defaultMaxBackoff, })), @@ -239,20 +239,20 @@ func newClientBuilder() *clientBuilder { func newClientBuilderFromRefreshableConfig(ctx context.Context, config RefreshableClientConfig, b *clientBuilder, reloadErrorSubmitter func(error), isHTTPClient bool) error { var err error - b.HTTP.ServiceNameTag, err = metrics.NewTag(MetricTagServiceName, config.CurrentClientConfig().ServiceName) + b.http.serviceNameTag, err = metrics.NewTag(MetricTagServiceName, config.CurrentClientConfig().ServiceName) if err != nil { return werror.WrapWithContextParams(ctx, err, "invalid service name metrics tag") } config.ServiceName().SubscribeToString(func(s string) { svc1log.FromContext(ctx).Warn("conjure-go-runtime: Service name changed but can not be live-reloaded.", - svc1log.SafeParam("existingServiceName", b.HTTP.ServiceNameTag.Value()), + svc1log.SafeParam("existingServiceName", b.http.serviceNameTag.Value()), svc1log.SafeParam("updatedServiceName", s)) }) if tlsConfig, err := subscribeTLSConfigUpdateWarning(ctx, config.Security()); err != nil { return err } else if tlsConfig != nil { - b.HTTP.TLSConfig = tlsConfig + b.http.tlsConfig = tlsConfig } refreshingParams, err := refreshable.NewMapValidatingRefreshable(config, func(i interface{}) (interface{}, error) { @@ -267,17 +267,17 @@ func newClientBuilderFromRefreshableConfig(ctx context.Context, config Refreshab return err } - b.HTTP.DialerParams = validParams.Dialer() - b.HTTP.TransportParams = validParams.Transport() - b.HTTP.Timeout = validParams.Timeout() - b.HTTP.DisableMetrics = validParams.DisableMetrics() - b.HTTP.MetricsTagProviders = append(b.HTTP.MetricsTagProviders, refreshableMetricsTagsProvider{validParams.MetricsTags()}) - b.HTTP.Middlewares = append(b.HTTP.Middlewares, + b.http.dialerParams = validParams.Dialer() + b.http.transportParams = validParams.Transport() + b.http.timeout = validParams.Timeout() + b.http.disableMetrics = validParams.DisableMetrics() + b.http.metricsTagProviders = append(b.http.metricsTagProviders, refreshableMetricsTagsProvider{validParams.MetricsTags()}) + b.http.middlewares = append(b.http.middlewares, newAuthTokenMiddlewareFromRefreshable(validParams.APIToken()), newBasicAuthMiddlewareFromRefreshable(validParams.BasicAuth())) - b.URIs = validParams.URIs() - b.MaxAttempts = validParams.MaxAttempts() - b.RetryParams = validParams.Retry() + b.uris = validParams.URIs() + b.maxAttempts = validParams.MaxAttempts() + b.retryParams = validParams.Retry() return nil } diff --git a/conjure-go-client/httpclient/client_params.go b/conjure-go-client/httpclient/client_params.go index 9945c79e..7ed7fc5f 100644 --- a/conjure-go-client/httpclient/client_params.go +++ b/conjure-go-client/httpclient/client_params.go @@ -65,7 +65,7 @@ func (f httpClientParamFunc) applyHTTPClient(b *httpClientBuilder) error { type clientOrHTTPClientParamFunc func(builder *httpClientBuilder) error func (f clientOrHTTPClientParamFunc) apply(b *clientBuilder) error { - return f(b.HTTP) + return f(b.http) } func (f clientOrHTTPClientParamFunc) applyHTTPClient(b *httpClientBuilder) error { @@ -112,7 +112,7 @@ func WithServiceName(serviceName string) ClientOrHTTPClientParam { if err != nil { return err } - b.ServiceNameTag = tag + b.serviceNameTag = tag return nil }) } @@ -122,7 +122,7 @@ func WithServiceName(serviceName string) ClientOrHTTPClientParam { // round trip, so it will see the request first and the response last. func WithMiddleware(h Middleware) ClientOrHTTPClientParam { return clientOrHTTPClientParamFunc(func(b *httpClientBuilder) error { - b.Middlewares = append(b.Middlewares, h) + b.middlewares = append(b.middlewares, h) return nil }) } @@ -170,8 +170,8 @@ func WithOverrideRequestHost(host string) ClientOrHTTPClientParam { // The serviceName will appear as the "service-name" tag. func WithMetrics(tagProviders ...TagsProvider) ClientOrHTTPClientParam { return clientOrHTTPClientParamFunc(func(b *httpClientBuilder) error { - b.DisableMetrics = refreshable.NewBool(refreshable.NewDefaultRefreshable(false)) - b.MetricsTagProviders = append(b.MetricsTagProviders, tagProviders...) + b.disableMetrics = refreshable.NewBool(refreshable.NewDefaultRefreshable(false)) + b.metricsTagProviders = append(b.metricsTagProviders, tagProviders...) return nil }) } @@ -180,7 +180,7 @@ func WithMetrics(tagProviders ...TagsProvider) ClientOrHTTPClientParam { // This prevents allocating a new byte buffer for every request. func WithBytesBufferPool(pool bytesbuffers.Pool) ClientParam { return clientParamFunc(func(b *clientBuilder) error { - b.BytesBufferPool = pool + b.bytesBufferPool = pool return nil }) } @@ -191,7 +191,7 @@ func WithBytesBufferPool(pool bytesbuffers.Pool) ClientParam { // If errMiddleware is not nil, it is invoked on the recovered object. func WithDisablePanicRecovery() ClientOrHTTPClientParam { return clientOrHTTPClientParamFunc(func(b *httpClientBuilder) error { - b.DisableRecovery = true + b.disableRecovery = true return nil }) } @@ -205,7 +205,7 @@ func WithDisablePanicRecovery() ClientOrHTTPClientParam { // trace information is propagate. This will not create a span if one does not exist. func WithDisableTracing() ClientOrHTTPClientParam { return clientOrHTTPClientParamFunc(func(b *httpClientBuilder) error { - b.CreateRequestSpan = false + b.createRequestSpan = false return nil }) } @@ -215,7 +215,7 @@ func WithDisableTracing() ClientOrHTTPClientParam { // then the client will attach this traceId as a header for future services to do the same if desired func WithDisableTraceHeaderPropagation() ClientOrHTTPClientParam { return clientOrHTTPClientParamFunc(func(b *httpClientBuilder) error { - b.InjectTraceHeaders = false + b.injectTraceHeaders = false return nil }) } @@ -224,7 +224,7 @@ func WithDisableTraceHeaderPropagation() ClientOrHTTPClientParam { // If unset, the client defaults to 1 minute. func WithHTTPTimeout(timeout time.Duration) ClientOrHTTPClientParam { return clientOrHTTPClientParamFunc(func(b *httpClientBuilder) error { - b.Timeout = refreshable.NewDuration(refreshable.NewDefaultRefreshable(timeout)) + b.timeout = refreshable.NewDuration(refreshable.NewDefaultRefreshable(timeout)) return nil }) } @@ -233,7 +233,7 @@ func WithHTTPTimeout(timeout time.Duration) ClientOrHTTPClientParam { // the transport with http2.ConfigureTransport. func WithDisableHTTP2() ClientOrHTTPClientParam { return clientOrHTTPClientParamFunc(func(b *httpClientBuilder) error { - b.TransportParams = refreshingclient.ConfigureTransport(b.TransportParams, func(p refreshingclient.TransportParams) refreshingclient.TransportParams { + b.transportParams = refreshingclient.ConfigureTransport(b.transportParams, func(p refreshingclient.TransportParams) refreshingclient.TransportParams { p.DisableHTTP2 = true return p }) @@ -251,7 +251,7 @@ func WithDisableHTTP2() ClientOrHTTPClientParam { // If unset, the client defaults to 30 seconds, if HTTP2 is enabled. func WithHTTP2ReadIdleTimeout(timeout time.Duration) ClientOrHTTPClientParam { return clientOrHTTPClientParamFunc(func(b *httpClientBuilder) error { - b.TransportParams = refreshingclient.ConfigureTransport(b.TransportParams, func(p refreshingclient.TransportParams) refreshingclient.TransportParams { + b.transportParams = refreshingclient.ConfigureTransport(b.transportParams, func(p refreshingclient.TransportParams) refreshingclient.TransportParams { p.HTTP2ReadIdleTimeout = timeout return p }) @@ -265,7 +265,7 @@ func WithHTTP2ReadIdleTimeout(timeout time.Duration) ClientOrHTTPClientParam { // If unset, the client defaults to 15 seconds, if HTTP/2 is enabled and the ReadIdleTimeout is > 0. func WithHTTP2PingTimeout(timeout time.Duration) ClientOrHTTPClientParam { return clientOrHTTPClientParamFunc(func(b *httpClientBuilder) error { - b.TransportParams = refreshingclient.ConfigureTransport(b.TransportParams, func(p refreshingclient.TransportParams) refreshingclient.TransportParams { + b.transportParams = refreshingclient.ConfigureTransport(b.transportParams, func(p refreshingclient.TransportParams) refreshingclient.TransportParams { p.HTTP2PingTimeout = timeout return p }) @@ -277,7 +277,7 @@ func WithHTTP2PingTimeout(timeout time.Duration) ClientOrHTTPClientParam { // will maintain. If unset, the client defaults to 200. func WithMaxIdleConns(conns int) ClientOrHTTPClientParam { return clientOrHTTPClientParamFunc(func(b *httpClientBuilder) error { - b.TransportParams = refreshingclient.ConfigureTransport(b.TransportParams, func(p refreshingclient.TransportParams) refreshingclient.TransportParams { + b.transportParams = refreshingclient.ConfigureTransport(b.transportParams, func(p refreshingclient.TransportParams) refreshingclient.TransportParams { p.MaxIdleConns = conns return p }) @@ -289,7 +289,7 @@ func WithMaxIdleConns(conns int) ClientOrHTTPClientParam { // will maintain per destination. If unset, the client defaults to 100. func WithMaxIdleConnsPerHost(conns int) ClientOrHTTPClientParam { return clientOrHTTPClientParamFunc(func(b *httpClientBuilder) error { - b.TransportParams = refreshingclient.ConfigureTransport(b.TransportParams, func(p refreshingclient.TransportParams) refreshingclient.TransportParams { + b.transportParams = refreshingclient.ConfigureTransport(b.transportParams, func(p refreshingclient.TransportParams) refreshingclient.TransportParams { p.MaxIdleConnsPerHost = conns return p }) @@ -302,11 +302,11 @@ func WithMaxIdleConnsPerHost(conns int) ClientOrHTTPClientParam { // If unset, the default is http.ProxyFromEnvironment. func WithNoProxy() ClientOrHTTPClientParam { return clientOrHTTPClientParamFunc(func(b *httpClientBuilder) error { - b.DialerParams = refreshingclient.ConfigureDialer(b.DialerParams, func(p refreshingclient.DialerParams) refreshingclient.DialerParams { + b.dialerParams = refreshingclient.ConfigureDialer(b.dialerParams, func(p refreshingclient.DialerParams) refreshingclient.DialerParams { p.SocksProxyURL = nil return p }) - b.TransportParams = refreshingclient.ConfigureTransport(b.TransportParams, func(p refreshingclient.TransportParams) refreshingclient.TransportParams { + b.transportParams = refreshingclient.ConfigureTransport(b.transportParams, func(p refreshingclient.TransportParams) refreshingclient.TransportParams { p.HTTPProxyURL = nil p.ProxyFromEnvironment = false return p @@ -319,7 +319,7 @@ func WithNoProxy() ClientOrHTTPClientParam { // the Go standard library's http.ProxyFromEnvironment. func WithProxyFromEnvironment() ClientOrHTTPClientParam { return clientOrHTTPClientParamFunc(func(b *httpClientBuilder) error { - b.TransportParams = refreshingclient.ConfigureTransport(b.TransportParams, func(p refreshingclient.TransportParams) refreshingclient.TransportParams { + b.transportParams = refreshingclient.ConfigureTransport(b.transportParams, func(p refreshingclient.TransportParams) refreshingclient.TransportParams { p.ProxyFromEnvironment = true return p }) @@ -336,12 +336,12 @@ func WithProxyURL(proxyURLString string) ClientOrHTTPClientParam { } switch proxyURL.Scheme { case "http", "https": - b.TransportParams = refreshingclient.ConfigureTransport(b.TransportParams, func(p refreshingclient.TransportParams) refreshingclient.TransportParams { + b.transportParams = refreshingclient.ConfigureTransport(b.transportParams, func(p refreshingclient.TransportParams) refreshingclient.TransportParams { p.HTTPProxyURL = proxyURL return p }) case "socks5", "socks5h": - b.DialerParams = refreshingclient.ConfigureDialer(b.DialerParams, func(p refreshingclient.DialerParams) refreshingclient.DialerParams { + b.dialerParams = refreshingclient.ConfigureDialer(b.dialerParams, func(p refreshingclient.DialerParams) refreshingclient.DialerParams { p.SocksProxyURL = proxyURL return p }) @@ -357,9 +357,9 @@ func WithProxyURL(proxyURLString string) ClientOrHTTPClientParam { func WithTLSConfig(conf *tls.Config) ClientOrHTTPClientParam { return clientOrHTTPClientParamFunc(func(b *httpClientBuilder) error { if conf == nil { - b.TLSConfig = nil + b.tlsConfig = nil } else { - b.TLSConfig = conf.Clone() + b.tlsConfig = conf.Clone() } return nil }) @@ -369,8 +369,8 @@ func WithTLSConfig(conf *tls.Config) ClientOrHTTPClientParam { // This option should only be used in clients that have way to establish trust with servers. func WithTLSInsecureSkipVerify() ClientOrHTTPClientParam { return clientOrHTTPClientParamFunc(func(b *httpClientBuilder) error { - if b.TLSConfig != nil { - b.TLSConfig.InsecureSkipVerify = true + if b.tlsConfig != nil { + b.tlsConfig.InsecureSkipVerify = true } return nil }) @@ -380,7 +380,7 @@ func WithTLSInsecureSkipVerify() ClientOrHTTPClientParam { // If unset, the client defaults to 90 seconds. func WithDialTimeout(timeout time.Duration) ClientOrHTTPClientParam { return clientOrHTTPClientParamFunc(func(b *httpClientBuilder) error { - b.DialerParams = refreshingclient.ConfigureDialer(b.DialerParams, func(p refreshingclient.DialerParams) refreshingclient.DialerParams { + b.dialerParams = refreshingclient.ConfigureDialer(b.dialerParams, func(p refreshingclient.DialerParams) refreshingclient.DialerParams { p.DialTimeout = timeout return p }) @@ -392,7 +392,7 @@ func WithDialTimeout(timeout time.Duration) ClientOrHTTPClientParam { // If unset, the client defaults to 90 seconds. func WithIdleConnTimeout(timeout time.Duration) ClientOrHTTPClientParam { return clientOrHTTPClientParamFunc(func(b *httpClientBuilder) error { - b.TransportParams = refreshingclient.ConfigureTransport(b.TransportParams, func(p refreshingclient.TransportParams) refreshingclient.TransportParams { + b.transportParams = refreshingclient.ConfigureTransport(b.transportParams, func(p refreshingclient.TransportParams) refreshingclient.TransportParams { p.IdleConnTimeout = timeout return p }) @@ -404,7 +404,7 @@ func WithIdleConnTimeout(timeout time.Duration) ClientOrHTTPClientParam { // If unset, the client defaults to 10 seconds. func WithTLSHandshakeTimeout(timeout time.Duration) ClientOrHTTPClientParam { return clientOrHTTPClientParamFunc(func(b *httpClientBuilder) error { - b.TransportParams = refreshingclient.ConfigureTransport(b.TransportParams, func(p refreshingclient.TransportParams) refreshingclient.TransportParams { + b.transportParams = refreshingclient.ConfigureTransport(b.transportParams, func(p refreshingclient.TransportParams) refreshingclient.TransportParams { p.TLSHandshakeTimeout = timeout return p }) @@ -417,7 +417,7 @@ func WithTLSHandshakeTimeout(timeout time.Duration) ClientOrHTTPClientParam { // If unset, the client defaults to 1 second. func WithExpectContinueTimeout(timeout time.Duration) ClientOrHTTPClientParam { return clientOrHTTPClientParamFunc(func(b *httpClientBuilder) error { - b.TransportParams = refreshingclient.ConfigureTransport(b.TransportParams, func(p refreshingclient.TransportParams) refreshingclient.TransportParams { + b.transportParams = refreshingclient.ConfigureTransport(b.transportParams, func(p refreshingclient.TransportParams) refreshingclient.TransportParams { p.ExpectContinueTimeout = timeout return p }) @@ -430,7 +430,7 @@ func WithExpectContinueTimeout(timeout time.Duration) ClientOrHTTPClientParam { // the client defaults to having no response header timeout. func WithResponseHeaderTimeout(timeout time.Duration) ClientOrHTTPClientParam { return clientOrHTTPClientParamFunc(func(b *httpClientBuilder) error { - b.TransportParams = refreshingclient.ConfigureTransport(b.TransportParams, func(p refreshingclient.TransportParams) refreshingclient.TransportParams { + b.transportParams = refreshingclient.ConfigureTransport(b.transportParams, func(p refreshingclient.TransportParams) refreshingclient.TransportParams { p.ResponseHeaderTimeout = timeout return p }) @@ -442,7 +442,7 @@ func WithResponseHeaderTimeout(timeout time.Duration) ClientOrHTTPClientParam { // If unset, the client defaults to 30 seconds. func WithKeepAlive(keepAlive time.Duration) ClientOrHTTPClientParam { return clientOrHTTPClientParamFunc(func(b *httpClientBuilder) error { - b.DialerParams = refreshingclient.ConfigureDialer(b.DialerParams, func(p refreshingclient.DialerParams) refreshingclient.DialerParams { + b.dialerParams = refreshingclient.ConfigureDialer(b.dialerParams, func(p refreshingclient.DialerParams) refreshingclient.DialerParams { p.KeepAlive = keepAlive return p }) @@ -453,7 +453,7 @@ func WithKeepAlive(keepAlive time.Duration) ClientOrHTTPClientParam { // WithBaseURLs sets the base URLs for every request. This is meant to be used in conjunction with WithPath. func WithBaseURLs(urls []string) ClientParam { return clientParamFunc(func(b *clientBuilder) error { - b.URIs = refreshable.NewStringSlice(refreshable.NewDefaultRefreshable(urls)) + b.uris = refreshable.NewStringSlice(refreshable.NewDefaultRefreshable(urls)) return nil }) } @@ -461,7 +461,7 @@ func WithBaseURLs(urls []string) ClientParam { // WithRefreshableBaseURLs sets the base URLs for every request. This is meant to be used in conjunction with WithPath. func WithRefreshableBaseURLs(urls refreshable.StringSlice) ClientParam { return clientParamFunc(func(b *clientBuilder) error { - b.URIs = urls + b.uris = urls return nil }) } @@ -470,7 +470,7 @@ func WithRefreshableBaseURLs(urls refreshable.StringSlice) ClientParam { // Defaults to 2 seconds. <= 0 indicates no limit. func WithMaxBackoff(maxBackoff time.Duration) ClientParam { return clientParamFunc(func(b *clientBuilder) error { - b.RetryParams = refreshingclient.ConfigureRetry(b.RetryParams, func(p refreshingclient.RetryParams) refreshingclient.RetryParams { + b.retryParams = refreshingclient.ConfigureRetry(b.retryParams, func(p refreshingclient.RetryParams) refreshingclient.RetryParams { p.MaxBackoff = maxBackoff return p }) @@ -481,7 +481,7 @@ func WithMaxBackoff(maxBackoff time.Duration) ClientParam { // WithInitialBackoff sets the initial backoff between retried calls to the same URI. Defaults to 250ms. func WithInitialBackoff(initialBackoff time.Duration) ClientParam { return clientParamFunc(func(b *clientBuilder) error { - b.RetryParams = refreshingclient.ConfigureRetry(b.RetryParams, func(p refreshingclient.RetryParams) refreshingclient.RetryParams { + b.retryParams = refreshingclient.ConfigureRetry(b.retryParams, func(p refreshingclient.RetryParams) refreshingclient.RetryParams { p.InitialBackoff = initialBackoff return p }) @@ -496,7 +496,7 @@ func WithInitialBackoff(initialBackoff time.Duration) ClientParam { func WithMaxRetries(maxTransportRetries int) ClientParam { return clientParamFunc(func(b *clientBuilder) error { attempts := maxTransportRetries + 1 - b.MaxAttempts = refreshable.NewIntPtr(refreshable.NewDefaultRefreshable(&attempts)) + b.maxAttempts = refreshable.NewIntPtr(refreshable.NewDefaultRefreshable(&attempts)) return nil }) } @@ -507,7 +507,7 @@ func WithUnlimitedRetries() ClientParam { return clientParamFunc(func(b *clientBuilder) error { // max attempts of 0 indicates no limit attempts := 0 - b.MaxAttempts = refreshable.NewIntPtr(refreshable.NewDefaultRefreshable(&attempts)) + b.maxAttempts = refreshable.NewIntPtr(refreshable.NewDefaultRefreshable(&attempts)) return nil }) } @@ -516,7 +516,7 @@ func WithUnlimitedRetries() ClientParam { // error to a non-nil value in the case of >= 400 HTTP response. func WithDisableRestErrors() ClientParam { return clientParamFunc(func(b *clientBuilder) error { - b.ErrorDecoder = nil + b.errorDecoder = nil return nil }) } @@ -524,7 +524,7 @@ func WithDisableRestErrors() ClientParam { // WithDisableKeepAlives disables keep alives on the http transport func WithDisableKeepAlives() ClientOrHTTPClientParam { return clientOrHTTPClientParamFunc(func(b *httpClientBuilder) error { - b.TransportParams = refreshingclient.ConfigureTransport(b.TransportParams, func(p refreshingclient.TransportParams) refreshingclient.TransportParams { + b.transportParams = refreshingclient.ConfigureTransport(b.transportParams, func(p refreshingclient.TransportParams) refreshingclient.TransportParams { p.DisableKeepAlives = true return p }) @@ -534,7 +534,7 @@ func WithDisableKeepAlives() ClientOrHTTPClientParam { func WithErrorDecoder(errorDecoder ErrorDecoder) ClientParam { return clientParamFunc(func(b *clientBuilder) error { - b.ErrorDecoder = errorDecoder + b.errorDecoder = errorDecoder return nil }) } @@ -552,7 +552,7 @@ func WithBasicAuth(user, password string) ClientParam { // Deprecated: This param is a no-op as balanced URI scoring is the default behavior. func WithBalancedURIScoring() ClientParam { return clientParamFunc(func(b *clientBuilder) error { - b.URIScorerBuilder = func(uris []string) internal.URIScoringMiddleware { + b.uriScorerBuilder = func(uris []string) internal.URIScoringMiddleware { return internal.NewBalancedURIScoringMiddleware(uris, func() int64 { return time.Now().UnixNano() }) @@ -564,7 +564,7 @@ func WithBalancedURIScoring() ClientParam { // WithRandomURIScoring adds middleware that randomizes the order URIs are prioritized in for each request. func WithRandomURIScoring() ClientParam { return clientParamFunc(func(b *clientBuilder) error { - b.URIScorerBuilder = func(uris []string) internal.URIScoringMiddleware { + b.uriScorerBuilder = func(uris []string) internal.URIScoringMiddleware { return internal.NewRandomURIScoringMiddleware(uris, func() int64 { return time.Now().UnixNano() }) diff --git a/conjure-go-client/httpclient/client_params_test.go b/conjure-go-client/httpclient/client_params_test.go index 56d20ee9..787f875d 100644 --- a/conjure-go-client/httpclient/client_params_test.go +++ b/conjure-go-client/httpclient/client_params_test.go @@ -113,7 +113,7 @@ func TestBuilder(t *testing.T) { }, }, { - Name: "TLSConfig", + Name: "tlsConfig", Param: WithTLSConfig(&tls.Config{InsecureSkipVerify: true}), Test: func(t *testing.T, client *clientImpl) { transport, _ := unwrapTransport(client.client.CurrentHTTPClient().Transport) @@ -121,7 +121,7 @@ func TestBuilder(t *testing.T) { }, }, { - Name: "Nil TLSConfig", + Name: "Nil tlsConfig", Param: WithTLSConfig(nil), Test: func(t *testing.T, client *clientImpl) { // No-op: passing nil should not cause panic diff --git a/conjure-go-client/httpclient/config.go b/conjure-go-client/httpclient/config.go index 99face43..22077477 100644 --- a/conjure-go-client/httpclient/config.go +++ b/conjure-go-client/httpclient/config.go @@ -153,7 +153,7 @@ func (c ServicesConfig) ClientConfig(serviceName string) ClientConfig { } // MergeClientConfig merges two instances of ClientConfig, preferring values from conf over defaults. -// The ServiceName field is not affected, and is expected to be set in the config before building a Client. +// The serviceName field is not affected, and is expected to be set in the config before building a Client. func MergeClientConfig(conf, defaults ClientConfig) ClientConfig { if len(conf.URIs) == 0 { conf.URIs = defaults.URIs diff --git a/conjure-go-client/httpclient/config_refreshable_test.go b/conjure-go-client/httpclient/config_refreshable_test.go index 60c9f477..4b1aeb53 100644 --- a/conjure-go-client/httpclient/config_refreshable_test.go +++ b/conjure-go-client/httpclient/config_refreshable_test.go @@ -55,8 +55,8 @@ func TestRefreshableClientConfig(t *testing.T) { assert.IsType(t, recoveryMiddleware{}, initialMiddlewares[0]) if assert.IsType(t, traceMiddleware{}, initialMiddlewares[1]) { traceM := initialMiddlewares[1].(traceMiddleware) - assert.True(t, traceM.CreateRequestSpan) - assert.True(t, traceM.InjectHeaders) + assert.True(t, traceM.createRequestSpan) + assert.True(t, traceM.injectHeaders) } if assert.IsType(t, &metricsMiddleware{}, initialMiddlewares[2]) { metricsM := initialMiddlewares[2].(*metricsMiddleware) diff --git a/conjure-go-client/httpclient/trace.go b/conjure-go-client/httpclient/trace.go index 867b4daa..30bd97c3 100644 --- a/conjure-go-client/httpclient/trace.go +++ b/conjure-go-client/httpclient/trace.go @@ -26,21 +26,21 @@ import ( // Only if the RPC method name is set does the middleware create a new span (with that name) for the // duration of the request. type traceMiddleware struct { - ServiceName string - CreateRequestSpan bool - InjectHeaders bool + serviceName string + createRequestSpan bool + injectHeaders bool } func (t traceMiddleware) RoundTrip(req *http.Request, next http.RoundTripper) (*http.Response, error) { ctx := req.Context() span := wtracing.SpanFromContext(ctx) - if t.CreateRequestSpan { + if t.createRequestSpan { // Create a child span if a method name is set. Otherwise, fall through and just inject the parent span's headers. if method := getRPCMethodName(req.Context()); method != "" { span, ctx = wtracing.StartSpanFromContext(ctx, wtracing.TracerFromContext(ctx), method, wtracing.WithKind(wtracing.Client), - wtracing.WithRemoteEndpoint(&wtracing.Endpoint{ServiceName: t.ServiceName})) + wtracing.WithRemoteEndpoint(&wtracing.Endpoint{ServiceName: t.serviceName})) if span != nil { defer span.Finish() } @@ -48,7 +48,7 @@ func (t traceMiddleware) RoundTrip(req *http.Request, next http.RoundTripper) (* } } - if t.InjectHeaders { + if t.injectHeaders { if span != nil { b3.SpanInjector(req)(span.Context()) } else { From 41b0e5b67d723d323320029517d898f048e1d9f4 Mon Sep 17 00:00:00 2001 From: svc-changelog Date: Fri, 6 Oct 2023 18:59:33 +0000 Subject: [PATCH 2/2] Add generated changelog entries --- changelog/@unreleased/pr-547.v2.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelog/@unreleased/pr-547.v2.yml diff --git a/changelog/@unreleased/pr-547.v2.yml b/changelog/@unreleased/pr-547.v2.yml new file mode 100644 index 00000000..2d1c1749 --- /dev/null +++ b/changelog/@unreleased/pr-547.v2.yml @@ -0,0 +1,5 @@ +type: improvement +improvement: + description: Unexport field of unexported and non-serialized structs + links: + - https://github.com/palantir/conjure-go-runtime/pull/547