core

package module
v0.0.0-...-d960042 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: MIT Imports: 14 Imported by: 7

README

CoreGO

Common library for Devotion's GO libraries & tools (Goald, Aldev...).

Mainly utility functions around handling files, collections, strings, etc.

Documentation

Index

Constants

View Source
const RFC3339Milli = "2006-01-02T15:04:05.000Z07:00"

custom time format, on top of the most used RFC3339

Variables

This section is empty.

Functions

func BoolToString

func BoolToString(value bool) string

BoolToString converts a boolean to a string

func CopyCmd

func CopyCmd() string

func DateToString

func DateToString(value *time.Time) string

DateToString converts a date to a string

func DirExists

func DirExists(pathParts ...string) bool

DirExists checks if a file exists at the specified path.

func EnsureDir

func EnsureDir(pathElem ...string) string

EnsureDir makes sure the directory with the given path elements exists

func EnsureModTime

func EnsureModTime(filePath string) time.Time

Returns the given file's modification time, or panics

func EnsureNoDir

func EnsureNoDir(pathElem ...string) string

EnsureNoDir removes the directory with the given path elements

func FileExists

func FileExists(pathParts ...string) bool

FileExists checks if a file exists at the specified path.

func Float32ToString

func Float32ToString(value float32) string

Float32ToString converts a float32 to a string

func Float64ToString

func Float64ToString(value float64) string

Float64ToString converts a float64 to a string

func GetFirstMapValue

func GetFirstMapValue[K cmp.Ordered, V any](m map[K]V) (value V)

GetFirstMapValue returns the value corresponding to the first key, having sorted the keys beforehand

func GetOneMapValue

func GetOneMapValue[K cmp.Ordered, V any](m map[K]V) (value V)

GetOneMapValue randomly returns a value from the map

func GetSortedKeys

func GetSortedKeys[K cmp.Ordered, V any](m map[K]V) (keys []K)

GetSortedKeys returns a sorted slice of keys from a map. K must be a comparable type, which is a constraint satisfied by all types that can be map keys.

func GetSortedValues

func GetSortedValues[K cmp.Ordered, V any](m map[K]V) (values []V)

GetSortedKeys returns a sorted slice of values from a map. K must be a comparable type, which is a constraint satisfied by all types that can be map keys.

func IfThenElse

func IfThenElse[T any](condition bool, valueIfTrue, valueIfFalse T) T

IfThenElse returns the valueIfTrue if the condition is true, otherwise it returns the valueIfFalse

func InSlice

func InSlice[V comparable](s []V, el V) bool

InSlice returns true if the slice s contains the given element el

func Int64ToString

func Int64ToString(value int64) string

Int64ToString converts a int64 to a string

func IntToString

func IntToString(value int) string

IntToString converts a int to a string

func IsLinux

func IsLinux() bool

func IsWindows

func IsWindows() bool

func KebabToPascal

func KebabToPascal(s string) string

KebabToPascal converts a kebab-case string to PascalCase

func MapFn

func MapFn[T, U any](input []T, transform func(T) U) []U

Generic Map function for slices

func MoveCmd

func MoveCmd() string

func Now

func Now() *time.Time

Now returns the current time

func PanicIfErr

func PanicIfErr(err error)

PanicIfErr panics if the error is not nil

func PanicMsg

func PanicMsg(str string, params ...any)

PanicMsg panics with the given message

func PanicMsgIf

func PanicMsgIf(cond bool, str string, params ...any)

PanicMsgIf panics with the given message if the condition is true

func PanicMsgIfErr

func PanicMsgIfErr(err error, str string, params ...any)

PanicMsgIfErr panics with the given message if the error is not nil

func PascalToCamel

func PascalToCamel(s string) string

PascalToCamel converts a PascalCase string to camelCase.

func PascalToKebab

func PascalToKebab(s string) string

PascalToKebab converts a PascalCase string to kebab-case.

func PascalToSnake

func PascalToSnake(s string) string

PascalToSnake converts a PascalCase string to snake_case.

func RandomString

func RandomString(length int) string

RandomString generates a random string of the given length

func ReadFile

func ReadFile(filename string, failIfNotExist bool) []byte

ReadFile reads the file with the given path and returns the bytes

func ReadFileFromJSON

func ReadFileFromJSON[T any, Y *T](filename string, obj Y, failIfNotExist bool) Y

ReadFileFromJSON reads the file with the given path and unmarshals the JSON object

func ReadFileFromYAML

func ReadFileFromYAML[T any, Y *T](filename string, obj Y, failIfNotExist bool) Y

ReadFileFromYAML reads the file with the given path and unmarshals the YAML object

func RemoveCmd

func RemoveCmd() string

func ReplaceInFile

func ReplaceInFile(filename string, replacements map[string]string)

ReplaceInFile replaces the given replacements in the file with the given path

func StringToBool

func StringToBool(valueAsString, context string) bool

StringToBool converts a string to a boolean

func StringToDate

func StringToDate(valueAsString, context string) *time.Time

StringToDate converts a string to a date

func StringToFloat32

func StringToFloat32(valueAsString, context string) float32

StringToFloat32 converts a string to a float32

func StringToFloat64

func StringToFloat64(valueAsString, context string) float64

StringToFloat64 converts a string to a float64

func StringToInt

func StringToInt(valueAsString, context string) int

StringToInt converts a string to a int

func StringToInt64

func StringToInt64(valueAsString, context string) int64

StringToInt64 converts a string to a int64

func ToPascal

func ToPascal(s string) string

ToPascal converts string to PascalCase

func WriteBytesToFile

func WriteBytesToFile(filename string, bytes []byte)

WriteBytesToFile writes the given bytes to the file with the given path

func WriteJsonObjToFile

func WriteJsonObjToFile(filename string, obj any)

WriteJsonObjToFile writes the given JSON object to the file with the given path

func WriteStringToFile

func WriteStringToFile(filename string, content string, params ...any)

WriteStringToFile writes the given string to the file with the given path

func WriteToFile

func WriteToFile(content string, filepaths ...string)

WriteToFile writes the given content to the file with the given path

Types

This section is empty.

Jump to

Keyboard shortcuts

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