Help us shape the future of Go! Take the 2026 Go Developer Survey

utils

package
v0.49.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: Apache-2.0 Imports: 21 Imported by: 1

Documentation

Index

Constants

View Source
const (
	SubscriptionMode_STREAM               = "STREAM"
	SubscriptionMode_ONCE                 = "ONCE"
	SubscriptionMode_POLL                 = "POLL"
	SubscriptionStreamMode_TARGET_DEFINED = "TARGET_DEFINED"
	SubscriptionStreamMode_ON_CHANGE      = "ON_CHANGE"
	SubscriptionStreamMode_SAMPLE         = "SAMPLE"
)

Variables

View Source
var ErrConfig = errors.New("config error")

Functions

func CreateSubscribeRequest added in v0.42.1

func CreateSubscribeRequest(cfg *types.SubscriptionConfig, tc *types.TargetConfig, defaultEncoding string) (*gnmi.SubscribeRequest, error)

func GetConfigMaps added in v0.43.0

func GetConfigMaps(s store.Store[any]) (map[string]*types.TargetConfig, map[string]map[string]any, map[string]map[string]any, error)

func NewTokenProvider

func NewTokenProvider(clientID, clientSecret, tokenURL string) sarama.AccessTokenProvider

func RecoverMiddleware added in v0.49.0

func RecoverMiddleware(logger func() *slog.Logger) mux.MiddlewareFunc

RecoverMiddleware returns an HTTP middleware that recovers from panics in the wrapped handler. The panic is logged with the request method, path and matched route template, and a `500 Internal Server Error` JSON response is sent when the handler had not started writing a response yet.

Without it, net/http recovers the panic per connection: the client gets a reset connection with no status, and a handler that panics while holding a lock leaves it held.

The http.ErrAbortHandler sentinel is re-panicked, as net/http expects. logger is resolved per request so it may be nil until the server starts.

func SetSaramaLoggerOnce added in v0.46.0

func SetSaramaLoggerOnce(logger *slog.Logger, level slog.Level)

SetSaramaLoggerOnce configures Sarama's process-wide logger once. Sarama exposes this as a global variable, so kafka inputs and outputs must coordinate through the same sync.Once to avoid racing assignments during startup.

func SubscriptionConfigToNotification added in v0.49.0

func SubscriptionConfigToNotification(sub *types.SubscriptionConfig, e gnmi.Encoding) *gnmi.Notification

SubscriptionConfigToNotification converts a subscription configuration to a gNMI notification under the `gnmic` origin, in the requested encoding. Only JSON and JSON_IETF encodings are supported.

func SubscriptionOpts added in v0.42.1

func SubscriptionOpts(sc *types.SubscriptionConfig, tc *types.TargetConfig, defaultEncoding string) ([]api.GNMIOption, error)

func TargetConfigToNotification added in v0.49.0

func TargetConfigToNotification(tc *types.TargetConfig, e gnmi.Encoding) *gnmi.Notification

TargetConfigToNotification converts a target configuration to a gNMI notification under the `gnmic` origin, in the requested encoding. It is used by the gNMI server(s) to reply to Get requests with origin=gnmic and path elem `targets`.

func ValidateSubscriptionConfig added in v0.48.0

func ValidateSubscriptionConfig(sc *types.SubscriptionConfig) error

ValidateSubscriptionConfig reports semantic errors in a subscription config without modifying it. An empty mode, stream-mode or encoding is accepted: those take their default value when the subscribe request is built.

Types

type RegisteredExtensions added in v0.44.0

type RegisteredExtensions map[int32]string

func ParseRegisteredExtensions added in v0.44.0

func ParseRegisteredExtensions(pairs []string) (RegisteredExtensions, error)

type TokenProvider

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

TokenProvider is a simple struct that implements sarama.AccessTokenProvider.

func (*TokenProvider) Token

func (t *TokenProvider) Token() (*sarama.AccessToken, error)

Jump to

Keyboard shortcuts

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