util

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFileSuffix added in v1.9.0

func AddFileSuffix(filename, suffix string) string

AddFileSuffix adds a suffix between the file name and the file extension

func CopyFile

func CopyFile(src string, dest string) (int64, error)

CopyFile copy a file from src path to dest path

func DeleteFiles

func DeleteFiles(files []string)

DeleteFiles removes the given file list ignoring errors

func DownloadFile added in v1.9.0

func DownloadFile(ctx context.Context, url string) (filename, mediaType string, data []byte, err error)

DownloadFile downloads a file from the given url

func FileExists

func FileExists(path string) bool

FileExists checks whether the given path is a file

func FindLogFiles

func FindLogFiles(path string) ([]string, []string, error)

FindLogFiles returns the files and dates archived by date

func GetFieldNameByTag

func GetFieldNameByTag(s interface{}, tag, value string) string

GetFieldNameByTag returns the field name of struct that match the given tag and value

func GetMapWithoutPrefix added in v1.16.0

func GetMapWithoutPrefix(set map[string]string, prefix string) map[string]string

func GetOrElse added in v1.7.1

func GetOrElse(s string, def string) string

GetOrElse returns the given string if it's non-empty, or returns the default string.

func GetSystemDnsServer added in v1.7.1

func GetSystemDnsServer() string

GetSystemDnsServer returns the dns server used by local system

func IsDirectory added in v1.8.0

func IsDirectory(path string) (bool, error)

IsDirectory determines if a file represented by `path` is a directory or not

func Map2String

func Map2String(m map[string]string) string

Map2String turns the map into string. The key value pairs are separated by equal sign. Each pair is separated by new line character.

func Partition

func Partition(s string, sep string) (string, string, string)

Partition returns the left side of the separator, the separator and the right side of the separator.

func PruneByTag

func PruneByTag(in interface{}, value string, tag string) (interface{}, error)

PruneByTag returns a copy of "in" that only contains fields with the given tag and value

func ReadFileLines

func ReadFileLines(path string) ([]string, error)

ReadFileLines reads all lines in a file and returns a slice of string

func RenameFiles

func RenameFiles(old []string, new []string)

RenameFiles renames the given file list with new file list ignoring errors

func ResolveSVCB added in v1.15.0

func ResolveSVCB(ctx context.Context, host string, server string) (string, uint16, error)

ResolveSVCB resolves the SVCB resource record of a given host. SVCB RR provides the information needed to connect to a service. The function returns a string for the target IP or domain name, an uint16 for the port, and an error.

func RuneSizeInString added in v1.9.0

func RuneSizeInString(s string) []int

RuneSizeInString returns a slice of each character's size in the given string

func SplitExt

func SplitExt(path string) (string, string)

SplitExt splits the path into base name and file extension

func String2Map

func String2Map(s string) map[string]string

String2Map splits the string by new line character. Each line is partitioned by equal sign. The left side is the key while the right side is the value.

func ZipFiles

func ZipFiles(filename string, files []string) error

ZipFiles compresses the given file list to a zip file

Types

This section is empty.

Jump to

Keyboard shortcuts

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