cobragrpc

package
v2.0.0-...-9f8a4f6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2023 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Overview

Package cobragrpc implements a builder for registering flags and producing a Cobra RunFunc that configures a gRPC server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder is used to configure a gRPC server via Cobra.

func New

func New(serviceName string, opts ...Option) *Builder

New creates a Cobra RunFunc Builder for a gRPC server.

func (*Builder) ListenFromFlags

func (b *Builder) ListenFromFlags(cmd *cobra.Command, srv *grpc.Server) error

ListenFromFlags listens on the provided gRPC server using values configured in the provided command.

func (*Builder) RegisterFlags

func (b *Builder) RegisterFlags(flags *pflag.FlagSet)

RegisterFlags adds flags for configuring a gRPC server.

The following flags are added: - "$PREFIX-addr" - "$PREFIX-tls-cert-path" - "$PREFIX-tls-key-path" - "$PREFIX-max-conn-age"

func (*Builder) ServerFromFlags

func (b *Builder) ServerFromFlags(cmd *cobra.Command, opts ...grpc.ServerOption) (*grpc.Server, error)

ServerFromFlags creates an *grpc.Server as configured by the flags from RegisterFlags().

type Option

type Option func(*Builder)

Option is function used to configure a gRPC server within a Cobra RunFunc.

func WithDefaultAddress

func WithDefaultAddress(addr string) Option

WithDefaultAddress configures the default value of the address the server will listen at.

Defaults to ":50051"

func WithDefaultEnabled

func WithDefaultEnabled(enabled bool) Option

WithDefaultEnabled defines whether the server is enabled by default.

Defaults to "false".

func WithFlagPrefix

func WithFlagPrefix(flagPrefix string) Option

WithFlagPrefix defines prefix used with the generated flags.

Defaults to "grpc".

func WithLogger

func WithLogger(logger logr.Logger) Option

WithLogger configures logging of the configured gRPC server environment.

func WithPreRunLevel

func WithPreRunLevel(preRunLevel int) Option

WithPreRunLevel defines the logging level used for pre-run log messages.

Defaults to "debug".

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL