util

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2025 License: Apache-2.0, BSD-3-Clause Imports: 24 Imported by: 11

Documentation

Overview

*

  • Copyright 2022 Comcast Cable Communications Management, LLC *
  • Licensed under the Apache License, Version 2.0 (the "License");
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at *
  • http://www.apache.org/licenses/LICENSE-2.0 *
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an "AS IS" BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License. *
  • SPDX-License-Identifier: Apache-2.0

*

  • Copyright 2022 Comcast Cable Communications Management, LLC *
  • Licensed under the Apache License, Version 2.0 (the "License");
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at *
  • http://www.apache.org/licenses/LICENSE-2.0 *
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an "AS IS" BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License. *
  • SPDX-License-Identifier: Apache-2.0

*

  • Copyright 2022 Comcast Cable Communications Management, LLC *
  • Licensed under the Apache License, Version 2.0 (the "License");
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at *
  • http://www.apache.org/licenses/LICENSE-2.0 *
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an "AS IS" BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License. *
  • SPDX-License-Identifier: Apache-2.0

*

  • Copyright 2022 Comcast Cable Communications Management, LLC *
  • Licensed under the Apache License, Version 2.0 (the "License");
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at *
  • http://www.apache.org/licenses/LICENSE-2.0 *
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an "AS IS" BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License. *
  • SPDX-License-Identifier: Apache-2.0

*

  • Copyright 2022 Comcast Cable Communications Management, LLC *
  • Licensed under the Apache License, Version 2.0 (the "License");
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at *
  • http://www.apache.org/licenses/LICENSE-2.0 *
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an "AS IS" BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License. *
  • SPDX-License-Identifier: Apache-2.0

*

  • Copyright 2022 Comcast Cable Communications Management, LLC *
  • Licensed under the Apache License, Version 2.0 (the "License");
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at *
  • http://www.apache.org/licenses/LICENSE-2.0 *
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an "AS IS" BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License. *
  • SPDX-License-Identifier: Apache-2.0

*

  • Copyright 2022 Comcast Cable Communications Management, LLC *
  • Licensed under the Apache License, Version 2.0 (the "License");
  • you may not use this file except in compliance with the License.
  • You may obtain a copy of the License at *
  • http://www.apache.org/licenses/LICENSE-2.0 *
  • Unless required by applicable law or agreed to in writing, software
  • distributed under the License is distributed on an "AS IS" BASIS,
  • WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  • See the License for the specific language governing permissions and
  • limitations under the License. *
  • SPDX-License-Identifier: Apache-2.0

Index

Constants

View Source
const (
	INADDR4SZ = 4
)

Variables

View Source
var (
	TZ, _ = time.LoadLocation("UTC")
)

Functions

func AlphaNumericMacAddress

func AlphaNumericMacAddress(macAddress string) string

AlphaNumericMacAddress is converting MAC address to only alphanumeric

func ApiVersionGreaterOrEqual

func ApiVersionGreaterOrEqual(version string, value float32) bool

func CalculateHash

func CalculateHash(plainText string) string

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 ContainsInt

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

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

plan to remove it later

func ConvertIpBytesToString

func ConvertIpBytesToString(bbytes []byte) string

func Copy

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

func CreateConfigMapStringBool

func CreateConfigMapStringBool(conf *configuration.Config, s string) map[string]bool

func CreateConfigMapStringString

func CreateConfigMapStringString(conf *configuration.Config, s string) map[string]string

func CreateKeyValuePairsFromMap

func CreateKeyValuePairsFromMap(m map[string]string) string

func GenerateRandomCpeMac

func GenerateRandomCpeMac() string

func GetAuditId

func GetAuditId() string

func GetCRC32HashValue

func GetCRC32HashValue(text string) string

func GetEcmMacAddress

func GetEcmMacAddress(mac string) string

func GetEstbMacAddress

func GetEstbMacAddress(mac string) string

func GetIpAddress

func GetIpAddress(r *http.Request, ipAddress string, fields log.Fields) string

func GetIpAddressWithoutQueryParam

func GetIpAddressWithoutQueryParam(r *http.Request) (string, bool, bool)

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 Ipv4NetworkMask

func Ipv4NetworkMask(prefixLength int) net.IPMask

func Ipv6NetworkMask

func Ipv6NetworkMask(prefixLength int) net.IPMask

generate Ipv6 network mask string

func IsBlank

func IsBlank(str string) bool

func IsIPv4

func IsIPv4(ip net.IP) bool

check ip address is Ipv4 or Ipv6

func IsIPv4LiteralAddress

func IsIPv4LiteralAddress(src string) bool

*

  • @param src a String representing an IPv4 address in textual format
  • @return a boolean indicating whether src is an IPv4 literal address

func IsInSameNetwork

func IsInSameNetwork(ip1Str, ip2Str string, mask net.IPMask) (bool, error)

func IsUnknownValue

func IsUnknownValue(param string) bool

func IsValidAppSetting

func IsValidAppSetting(key string) bool

func IsValidMacAddress

func IsValidMacAddress(macaddr string) bool

func IsValidMacAddressForAdminService

func IsValidMacAddressForAdminService(macaddr string) bool

func IsVersionGreaterOrEqual

func IsVersionGreaterOrEqual(version string, value float64) 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
11:11:11:11:11:11
11111111111

:param value: A String :return: A String, upper case mac address, AABBCCDDEEFF ”'

func MACAddressValidatorForAS

func MACAddressValidatorForAS(macAddress string) (bool, error)

func MacAddrComplexFormat

func MacAddrComplexFormat(macaddr string) (string, error)

MacAddrComplexFormat is to convert mac address from XXXXXXXXXXX to XX:XX:XX:XX:// XXX

func NewStringSet

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

func NormalizeMacAddress

func NormalizeMacAddress(macAddress string) string

func PrettyJson

func PrettyJson(input interface{}) string

func PutIfValuePresent

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

func RandomDouble

func RandomDouble() float64

func RandomPercentage

func RandomPercentage() int

RandomPercentage returns a random integer between 0 and 99 (inclusive). WARNING: This function uses math/rand which is NOT cryptographically secure. It should ONLY be used for non-security critical operations like load balancing or gradual feature rollouts, never for security purposes, authentication, or encryption.

func RemoveNonAlphabeticSymbols

func RemoveNonAlphabeticSymbols(macAddress string) string

func StringAppendIfMissing

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

func StringElementsMatch

func StringElementsMatch(a, b []string) bool

func StringSliceEqual

func StringSliceEqual(a, b []string) bool

func TextToNumericFormatV4

func TextToNumericFormatV4(src string) []byte

* Converts IPv4 address in its textual presentation form * into its numeric binary form. * * @param src a String representing an IPv4 address in standard format * @return a byte array representing the IPv4 numeric address

func ToAlphaNumericString

func ToAlphaNumericString(str string) string

func ToColonMac

func ToColonMac(d string) string

func ToInt

func ToInt(itf interface{}) int

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 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)

func ValidateMac

func ValidateMac(mac string) bool

func XConfJSONMarshal

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

Types

type Dict

type Dict map[string]interface{}

func (Dict) Copy

func (d Dict) Copy() Dict

func (Dict) MsecsToTime

func (d Dict) MsecsToTime(fields ...string)

func (Dict) SelectByKeys

func (d Dict) SelectByKeys(names ...string) Dict

func (Dict) String

func (d Dict) String() string

func (Dict) TimeToMsecs

func (d Dict) TimeToMsecs(field string)

func (Dict) ToInt

func (d Dict) ToInt(fields ...string)

func (Dict) ToInt64

func (d Dict) ToInt64(fields ...string)

type Set

type Set map[string]struct{}

func NewSet

func NewSet(items ...string) Set

func (Set) Add

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

func (Set) Contains

func (s Set) Contains(obj string) bool

func (Set) IsEmpty

func (s Set) IsEmpty() bool

func (Set) Remove

func (s Set) Remove(x string)

func (Set) ToSlice

func (s Set) ToSlice() []string

Jump to

Keyboard shortcuts

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