utils

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2018 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// SafeStringsRegex will match any usernames, passwords or tokens in a string.
	SafeStringsRegex = regexp.MustCompile(`(?m)(username|password|token)=[\w=]+(&?)`)

	// StringSafer will replace sensitive values (username, password and token) with safed values.
	StringSafer = func(input string) string {
		ret := input
		if strings.HasPrefix(input, "username=") {
			ret = "username=REDACTED"
		} else if strings.HasPrefix(input, "password=") {
			ret = "password=REDACTED"
		} else if strings.HasPrefix(input, "token=") {
			ret = "token=bm90Zm9yeW91"
		}
		if strings.HasSuffix(input, "&") {
			return fmt.Sprintf("%s&", ret)
		}
		return ret
	}
)

Functions

func ChunkStringSlice

func ChunkStringSlice(sl []string, chunkSize int) [][]string

ChunkStringSlice will return a slice of slice of strings for the given chunkSize.

func Contains

func Contains(s []string, e string) bool

Contains returns true if the given element "e" is found inside the slice of strings "s".

func CountDigits

func CountDigits(i int) int

CountDigits will count the number of digits in an integer.

func Difference

func Difference(a, b []string) []string

Difference returns the elements in a that aren't in b

func GetFile

func GetFile(path string) (io.ReadCloser, string, error)

GetFile is a helper function to download/open and parse a file.

func GetM3U

func GetM3U(path string) (*m3uplus.Playlist, error)

GetM3U is a helper function to download/open and parse a M3U Plus file.

func GetStringMapKeys

func GetStringMapKeys(s map[string]struct{}) []string

GetStringMapKeys returns a slice of strings for the keys of a map.

func GetTCPAddr

func GetTCPAddr(key string) *net.TCPAddr

GetTCPAddr attempts to convert a string found via viper to a net.TCPAddr. Will panic on error.

func GetXMLTV

func GetXMLTV(path string) (*xmltv.TV, error)

GetXMLTV is a helper function to download/open and parse a XMLTV file.

func KebabCase

func KebabCase(s string) string

KebabCase converts a string into kebab case.

func PadNumberWithZeros

func PadNumberWithZeros(value int, expectedLength int) string

PadNumberWithZeros will pad the given value integer with 0's until expectedLength is met.

func SnakeCase

func SnakeCase(s string) string

SnakeCase converts a string into snake case.

Types

This section is empty.

Jump to

Keyboard shortcuts

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