utils

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetPackageName

func GetPackageName(directory string) string

GetPackageName returns the last part of the directory path as a package name. If the directory is empty, the function returns "main".

func JoinNonemptyStrings

func JoinNonemptyStrings(sep string, s ...string) string

JoinNonemptyStrings joins non-empty strings with a separator.

func NormalizePathItem added in v0.3.0

func NormalizePathItem(s string) string

NormalizePathItem converts a string to a valid path item.

The function removes invalid characters from the string, converts it to snake case. If string contains the invalid characters only, it is replaced by hash string of the original string to make it non-empty.

func OrderedKeysIter added in v0.3.0

func OrderedKeysIter[K cmp.Ordered, V any](m map[K]V) iter.Seq2[K, V]

OrderedKeysIter returns an iterator over the map's keys and values, in ascending order of the keys.

func ToGoFilePath

func ToGoFilePath(pathString string) string

ToGoFilePath converts any path-looking string to the valid path to Go source file path and returns it.

If the path is empty, the function returns a constant file name.

While converting, the function shortens the path by eliminating the dot parts, removes invalid characters from every part, converting the rest to snake case. If an item contains invalid characters only, it is replaced by hash string of the original string to make it non-empty. The last part also will have ".go" file extension.

func ToGolangName

func ToGolangName(rawString string, exported bool) string

ToGolangName converts any string to a valid Golang name. The exported argument determines if the result should be the exported name (start with an uppercase letter) or not.

This function removes the invalid characters from source string, converts it to camel case or pascal case, makes initialisms uppercase, ensuring that the result doesn't conflict with Golang reserved keywords.

func WithoutBy

func WithoutBy[T comparable, Slice ~[]T](collection Slice, exclude Slice, predicate func(a, b T) bool) Slice

WithoutBy returns slice excluding all given values executing the predicate function.

Types

This section is empty.

Jump to

Keyboard shortcuts

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