common

package
v0.1.15-rc.3 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package common provides shared helpers for StreamNative MCP Server.

Index

Constants

View Source
const (
	OptionsKey                        ContextKey = "snmcp-options"
	AnnotationStreamNativeCloudEngine            = "cloud.streamnative.io/engine"
	KeyPrefix                                    = "snmcp-token"
	TokenRefreshWindow                           = 5 * time.Minute
)

Common constants used for context keys and token handling.

Variables

This section is empty.

Functions

func ConvertToMapInterface

func ConvertToMapInterface(m map[string]string) map[string]interface{}

ConvertToMapInterface converts a map of strings to a map of interface values.

func ConvertToMapString

func ConvertToMapString(m map[string]interface{}) map[string]string

ConvertToMapString converts a map of interface values to a map of strings.

func GetEngineType

GetEngineType returns the Pulsar cluster is an Ursa engine or a Classic engine

func GetOptions

func GetOptions(ctx context.Context) *config.Options

GetOptions extracts the config options from the context.

func HasCachedValidToken

func HasCachedValidToken(cachedGrant *auth.AuthorizationGrant) (bool, error)

HasCachedValidToken returns whether the cached grant has a valid token.

func IsClusterAvailable

IsClusterAvailable checks if a PulsarCluster is available (ready)

func IsInstanceValid

IsInstanceValid checks if PulsarInstance has valid OAuth2 authentication configuration

func IsTokenAboutToExpire

func IsTokenAboutToExpire(cachedGrant *auth.AuthorizationGrant, window time.Duration) (bool, error)

IsTokenAboutToExpire reports whether the token expires within the window.

func OptionalParam

func OptionalParam[T any](arguments map[string]interface{}, paramName string) (T, bool)

OptionalParam returns an optional parameter from the request.

func OptionalParamArray

func OptionalParamArray[T any](arguments map[string]interface{}, paramName string) ([]T, bool)

OptionalParamArray returns an optional array parameter from the request.

func OptionalParamConfigs

func OptionalParamConfigs(arguments map[string]interface{}, paramName string) ([]string, bool)

OptionalParamConfigs gets an optional parameter as a list of key=value strings

func OptionalParamObject

func OptionalParamObject(arguments map[string]interface{}, name string) (map[string]interface{}, bool)

OptionalParamObject returns an optional object parameter from the request.

func ParseMessageConfigs

func ParseMessageConfigs(configs []string) (map[string]*string, error)

ParseMessageConfigs parses a list of key=value strings into a map

func RequiredParam

func RequiredParam[T comparable](arguments map[string]interface{}, p string) (T, error)

RequiredParam is a helper function that can be used to fetch a requested parameter from the request. It does the following checks: 1. Checks if the parameter is present in the request. 2. Checks if the parameter is of the expected type. 3. Checks if the parameter is not empty, i.e: non-zero value

func RequiredParamArray

func RequiredParamArray[T any](arguments map[string]interface{}, paramName string) ([]T, error)

RequiredParamArray returns a required array parameter from the request.

func RequiredParamObject

func RequiredParamObject(arguments map[string]interface{}, name string) (map[string]interface{}, error)

RequiredParamObject returns a required object parameter from the request.

Types

type ContextKey

type ContextKey string

ContextKey defines typed keys for context values.

Jump to

Keyboard shortcuts

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