util

package
v1.0.13 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	HeaderAuthorization        = "Authorization"
	HeaderUserAgent            = "User-Agent"
	HeaderIfNoneMatch          = "If-None-Match"
	HeaderFirmwareVersion      = "X-System-Firmware-Version"
	HeaderSupportedDocs        = "X-System-Supported-Docs"
	HeaderSupplementaryService = "X-System-SupplementaryService-Sync"
	HeaderModelName            = "X-System-Model-Name"
	HeaderProfileVersion       = "X-System-Telemetry-Profile-Version"
	HeaderPartnerID            = "X-System-PartnerID"
	HeaderAccountID            = "X-System-AccountID"
	HeaderXconfDataService     = "XconfDataService"
	HeaderXconfAdminService    = "XconfAdminService"
)
View Source
const (
	TelemetryTwoProfileJSONSchema = `` /* 19660-byte string literal not displayed */

)

Variables

View Source
var (
	SupportedPokeDocs = []string{"primary", "telemetry"}
)
View Source
var (
	TZ, _ = time.LoadLocation("UTC")
)
View Source
var TelemetryTwoProfileSchema *gojsonschema.Schema

Functions

func AddBodyParamsToContextMap

func AddBodyParamsToContextMap(body string, contextMap map[string]string)

func AddQueryParamsToContextMap

func AddQueryParamsToContextMap(r *http.Request, contextMap map[string]string)

func AlphaNumericMacAddress

func AlphaNumericMacAddress(macAddress string) string

AlphaNumericMacAddress is converting MAC address to only alphanumeric

func CaseInsensitiveContains

func CaseInsensitiveContains(data []string, x string) bool

func Contains

func Contains(collection interface{}, element interface{}) bool

func ContainsAny

func ContainsAny(collection1 []string, collection2 []string) bool

func ContainsIgnoreCase

func ContainsIgnoreCase(s, substr string) bool

func ContainsInt

func ContainsInt(data []int, x int) bool

TODO keep it for backward compatibility in "webconfig" for now

plan to remove it later

func Copy

func Copy(obj interface{}) (interface{}, error)

func FindEntryInContext

func FindEntryInContext(filterContext map[string]string, key string, exact bool) (value string, found bool)

func FindValidIpAddress

func FindValidIpAddress(req *http.Request, contextIpAddress string) string

* * Most important is IP from 'X-Forwarded-For' or 'HA-Forwarded-For' header. If it's valid we use it. * If not then check value from context. If valid - use it. * If not then read remote address from request info. If valid - use it. * At edge case when nothing above is a correct IP address then we fallback to '0.0.0.0' * @param contextIpAddress ip address from request context * @param req http request meta info

func GenerateRandomCpeMac

func GenerateRandomCpeMac() string

func GetAuditId

func GetAuditId() string

func GetEcmMacAddress

func GetEcmMacAddress(mac string) string

func GetEstbMacAddress

func GetEstbMacAddress(mac string) string

func GetTelemetryQueryString

func GetTelemetryQueryString(header http.Header, mac string) string

func GetTimestamp

func GetTimestamp(args ...time.Time) int64

GetTimestamp - return current timestamp in Millisecond in UTC timezone or convert specified time to Millisecond

func GetURLQueryParameterString

func GetURLQueryParameterString(kvs [][]string) (string, error)

REMINDER a 2-D slices/arrays of strings are chosen, instead of a map, to keep the params ordering

func HelpfulJSONUnmarshalErr

func HelpfulJSONUnmarshalErr(jsonBytes []byte, tag string, err error) string

HelpfulJSONUnmarshalErr just points near the location of json err when possible jsonStr is the string we tried to unmarshal tag is just a string identifying who ran into this err, will be part of the return string err is the original err got when unmarshalling return a string that contains the offset of the err location Copied from xap_proxy

func IsBlank

func IsBlank(str string) bool

func IsUnknownValue

func IsUnknownValue(param string) bool

func IsValidMacAddress

func IsValidMacAddress(macaddr string) bool

func JSONMarshal

func JSONMarshal(t interface{}) ([]byte, error)

JSONMarshal is used to marshal struct to string Without escaping special character like &, <, > Note: JSONMarshal will terminate each value with a newline

func MACAddressValidator

func MACAddressValidator(macAddress string) (bool, error)

MACAddressValidator method is to validate MAC address Validate inputs are:

11-11-11-11-11-11
11:11:11:11:11:11
1111.1111.1111
11111111111

func NewStringSet

func NewStringSet(collection []string) map[string]struct{}

func NormalizeMacAddress

func NormalizeMacAddress(macAddress string) string

Use this function only if you know the mac address is valid

func PutIfValuePresent

func PutIfValuePresent(m map[string]interface{}, k string, v interface{})

func RandomDouble

func RandomDouble() float64

func RandomPercentage

func RandomPercentage() int

func RemoveOneElementFromList

func RemoveOneElementFromList(ids []string, idToRemove string) []string

func StringAppendIfMissing

func StringAppendIfMissing(collection []string, s string) []string

func StringArrayContains

func StringArrayContains(collection []string, value string) bool

func StringCopySlice

func StringCopySlice(collection []string) []string

func StringElementsMatch

func StringElementsMatch(a, b []string) bool

func StringSliceContains

func StringSliceContains(s []string, searchterm string) bool

func ToAlphaNumericString

func ToAlphaNumericString(str string) string

func ToColonMac

func ToColonMac(d string) string

func UUIDFromTime

func UUIDFromTime(timestamp int64, node int64, clockSeq uint32) (gocql.UUID, error)

UUIDFromTime gocql method implementation

func UtcCurrentTimestamp

func UtcCurrentTimestamp() time.Time

UtcCurrentTimestamp - return current timestamp in UTC timezone

func UtcOffsetPriorMinTimestamp

func UtcOffsetPriorMinTimestamp(min int) int64

UtcOffsetPriorminTimestamp currect timestamp

func UtcOffsetTimestamp

func UtcOffsetTimestamp(sec int) time.Time

UtcOffsetTimestamp currect timestamp

func UtcTimeInNano

func UtcTimeInNano() int64

UtcTimeInNano - return current time in nano in UTC timezone

func ValidateAndNormalizeMacAddress

func ValidateAndNormalizeMacAddress(macaddr string) (string, error)

ValidateAndNormalizeMacAddress is to validate and convert MAC address to XX:XX:XX:XX:XX:XX

func ValidateCronDayAndMonth

func ValidateCronDayAndMonth(cronExpression string) error

func ValidatePokeQuery

func ValidatePokeQuery(values url.Values) (string, error)

func ValidateTelemetryTwoProfileJson

func ValidateTelemetryTwoProfileJson(json string) error

ValidateTelemetryTwoProfileJson validates JSON against the schema

func ValidateTimeFormat

func ValidateTimeFormat(timeStr string) error

func ValidateTimezoneList

func ValidateTimezoneList(timezoneList string) error

func XConfJSONMarshal

func XConfJSONMarshal(v interface{}, safeEncoding bool) ([]byte, error)

Types

type Set

type Set map[string]struct{}

func (Set) Add

func (s Set) Add(items ...string)

func (Set) Contains

func (s Set) Contains(x string) bool

func (Set) Remove

func (s Set) Remove(x string)

func (Set) ToSlice

func (s Set) ToSlice() []string

type StringMap

type StringMap map[string]string

func (StringMap) Keys

func (m StringMap) Keys() []string

Jump to

Keyboard shortcuts

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