cobrahttp

package
v4.0.0-...-7740553 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package cobrahttp implements a builder for registering flags and producing a Cobra RunFunc that configures an HTTP 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 an HTTP server via Cobra.

func New

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

New creates a Cobra RunFunc Builder for an HTTP server.

func (*Builder) ListenFromFlags

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

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

func (*Builder) RegisterFlags

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

RegisterFlags adds flags for configuring an HTTP server.

The following flags are added: - "$PREFIX-addr" - "$PREFIX-tls-cert-path" - "$PREFIX-tls-key-path" - "$PREFIX-enabled"

func (*Builder) ServerFromFlags

func (b *Builder) ServerFromFlags(cmd *cobra.Command) *http.Server

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

type Option

type Option func(b *Builder)

Option is function used to configure an HTTP 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 ":8443"

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 "http".

func WithHandler

func WithHandler(handler http.Handler) Option

WithHandler defines the handler used by the http.Server.

No handler is set by default.

func WithLogger

func WithLogger(logger logr.Logger) Option

WithLogger configures logging of the configured HTTP 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