utils

package
v1.4.5 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToString

func BytesToString(b []byte) string

BytesToString converts byte slice to string.

func CamelToSnake added in v1.3.1

func CamelToSnake(name string) string

func CondenseEmptyLines added in v0.2.2

func CondenseEmptyLines(s string) string

CondenseEmptyLines condenses multiple consecutive empty lines in a string to a single empty line, while preserving non-empty lines.

func CreateIfNotExists

func CreateIfNotExists(path string, isDir bool) error

CreateIfNotExists creates a file or a directory only if it does not already exist.

func DecodeRawUnicodeEscape

func DecodeRawUnicodeEscape(s string) string

func EnsureTrailingNewline added in v0.2.2

func EnsureTrailingNewline(s string) string

func IsExist

func IsExist(path string) bool

IsExist checks if a file or directory exists

func MakeDir

func MakeDir(dir string) error

func RelToCwd

func RelToCwd(path string) string

func RemoveDirIfExist added in v1.4.2

func RemoveDirIfExist(path string) error

func RemoveIfExist

func RemoveIfExist(path string) error

func ReplaceSubscript

func ReplaceSubscript(s string) string

func ReplaceSuperscript

func ReplaceSuperscript(s string) string

func SplitLines added in v1.3.1

func SplitLines(s string) []string

SplitLines splits a string into lines by '\n' or '\r\n'.

func StringToBytes

func StringToBytes(s string) []byte

StringToBytes converts string to byte slice.

func Truncate

func Truncate(filename string) error

func TruncateString added in v1.3.12

func TruncateString(s string, n int) string

TruncateString shortens a string longer than n by replacing the middle part with "...<truncated>..."

func WriteFile added in v1.3.1

func WriteFile(file string, content []byte) error

func WriteOrAppendFile added in v1.4.3

func WriteOrAppendFile(file string, content []byte) error

Types

type RateLimiter

type RateLimiter struct {
	// contains filtered or unexported fields
}

func NewRateLimiter

func NewRateLimiter(per time.Duration) *RateLimiter

func (*RateLimiter) Take added in v0.2.1

func (r *RateLimiter) Take()

Jump to

Keyboard shortcuts

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