{"modulePath":"github.com/dolfly/x","version":"v0.28.2","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package plugin\n\nPackage plugin provides shared utilities for building gRPC and HTTP plugin clients. Both transport types support authentication tokens, TLS configuration, custom headers (HTTP), and connection timeouts.\n\n## Constants\n\n```go\nconst (\n\t// GRPC is the transport type identifier for gRPC-based plugins.\n\tGRPC string = \"grpc\"\n\t// HTTP is the transport type identifier for HTTP-based plugins.\n\tHTTP string = \"http\"\n)\n```\n\n## Functions\n\n```go\nfunc HTTPClientTransport(c *http.Client) *http.Transport\n```\nHTTPClientTransport returns the \\*http.Transport underlying c, or nil if c's transport is not an \\*http.Transport. When the client was created with a non-empty Token, the \\*http.Transport is unwrapped from the tokenTransport wrapper. Callers that hold the client for a long time should call tr.CloseIdleConnections() when the client is no longer needed.\n\n```go\nfunc NewGRPCConn(addr string, opts *Options) (*grpc.ClientConn, error)\n```\nNewGRPCConn creates a gRPC client connection to addr. If opts is nil or opts.TLSConfig is nil, the connection uses insecure transport. When opts.Token is set, it is attached as per-RPC credentials.\n\n```go\nfunc NewHTTPClient(opts *Options) *http.Client\n```\nNewHTTPClient creates an http.Client from opts. If opts is nil, a default client with no timeout is returned. When opts.Token is set, the returned client's transport is wrapped so that each outgoing request carries an \"Authorization: Bearer \\\u003ctoken\u003e\" header (unless the caller has already set its own Authorization header). Use HTTPClientTransport to access the underlying \\*http.Transport and close idle connections when the client is no longer needed.\n\n## Types\n\n```go\ntype Option func(opts *Options)\n```\nOption configures Options.\n\n```go\nfunc HeaderOption(header http.Header) Option\n```\nHeaderOption sets custom HTTP headers sent with each request (HTTP transport only).\n\n```go\nfunc TLSConfigOption(cfg *tls.Config) Option\n```\nTLSConfigOption sets the TLS configuration for transport security.\n\n```go\nfunc TimeoutOption(timeout time.Duration) Option\n```\nTimeoutOption sets the request timeout (HTTP transport only).\n\n```go\nfunc TokenOption(token string) Option\n```\nTokenOption sets the authentication token sent with each request.\n\n```go\ntype Options struct {\n\tToken     string\n\tTLSConfig *tls.Config\n\tHeader    http.Header\n\tTimeout   time.Duration\n}\n```\nOptions holds the common configuration for gRPC and HTTP plugin clients.\n\n","path":"github.com/dolfly/x/internal/plugin","name":"plugin","synopsis":"Package plugin provides shared utilities for building gRPC and HTTP plugin clients.","isRedistributable":true}
