Skip to content

Migration: gRPC client dial factory → go/grpcclient

The gRPC client dial factory — the endpoint assembly and transport-credential selection that lived inside pkg/grpc's dialLocal — has been extracted out of go-tool-base into the standalone module gitlab.com/phpboyscout/go/grpcclient (v0.1.0). It is framework-free: it depends only on the gRPC SDK, go/tls and go/transit.

What changed

  • Nothing changes for GTB consumers. pkg/grpc.DialLocal(settings, tlsPair, opts…) keeps its exact signature and behaviour. It is now a thin adapter: it resolves the GTB-side port from ServerSettings and maps the local host + TLS pair onto a grpcclient.Target, then calls grpcclient.Dial. Callers — including pkg/gateway — are unaffected.
  • The new module exposes a first-class, server-decoupled target type:
type Target struct {
  Host string   // empty ⇒ loopback (localhost)
  Port int
  TLS  tls.Pair // go/tls pair
}
func Dial(t Target, opts ...grpc.DialOption) (*grpc.ClientConn, error)
  • The gRPC client interceptors (CircuitBreakerInterceptor, OTelClientHandler, …) are not moved — they already live in go/transit/grpc and are passed to Dial as dial options.
  • TLSClientCredentials and the server bootstraps stay in pkg/grpc (the server stack is Phase 5).

One behavioural refinement

The old dialLocal passed tlsPair.Cert to the credential builder unconditionally, so Enabled: true with an empty Cert produced an error (an attempt to read the file ""). grpcclient.Dial treats an enabled pair with an empty Cert as "trust the system roots" instead — the sensible generalisation. An enabled pair with a set but missing/invalid cert path still errors, exactly as before. GTB's ServerSettings-driven DialLocal always supplies a cert path when TLS is enabled, so this is invisible to GTB callers.

How to migrate

If you consume go-tool-base's pkg/grpc.DialLocal, do nothing — upgrade as usual.

If you want the gRPC dial factory without the framework, depend on the module directly:

go get gitlab.com/phpboyscout/go/[email protected]
import (
    "gitlab.com/phpboyscout/go/grpcclient"
    gtls "gitlab.com/phpboyscout/go/tls"
    transitgrpc "gitlab.com/phpboyscout/go/transit/grpc"
    "google.golang.org/grpc"
)

conn, err := grpcclient.Dial(
    grpcclient.Target{Host: "svc.internal", Port: 443, TLS: gtls.Pair{Enabled: true, Cert: "/etc/pki/ca.pem"}},
    grpc.WithChainUnaryInterceptor(transitgrpc.CircuitBreakerInterceptor(log, transitgrpc.DefaultCircuitBreakerConfig())),
    transitgrpc.OTelClientHandler(),
)

Notes