utils

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendSorted

func AppendSorted[T any](slice []T, value T, less func(a, b T) bool) []T

func AppendSortedOptimize

func AppendSortedOptimize[T any](slice []T, value T, less func(a, b T) bool) []T

func CamelToSnake

func CamelToSnake(s string) string
Example
package main

import (
	"github.com/primadi/lokstra/common/utils"
)

func main() {
	// Basic usage examples
	result1 := utils.CamelToSnake("camelCase")
	result2 := utils.CamelToSnake("PascalCase")
	result3 := utils.CamelToSnake("getUserName")
	result4 := utils.CamelToSnake("HTTPResponse")

	println(result1) // camel_case
	println(result2) // pascal_case
	println(result3) // get_user_name
	println(result4) // http_response
}

func CheckPasswordHash added in v0.3.0

func CheckPasswordHash(password, hash string) bool

func ClientIP added in v0.3.0

func ClientIP(r *http.Request) string

func CloneMap

func CloneMap[K comparable, V any](original map[K]V) map[K]V

func GetBasePath added in v0.3.3

func GetBasePath() string

func GetDurationFromMap

func GetDurationFromMap(settings map[string]any, key string, defaultValue any) time.Duration

func GetValueFromMap

func GetValueFromMap[T any](settings map[string]any, key string, defaultValue T) T

func HashPassword

func HashPassword(password string) (string, error)

func IsFileExists added in v0.6.7

func IsFileExists(path string) bool

func IsNil added in v0.3.0

func IsNil[T any](v T) bool

func NewSliceAndAppend added in v0.7.9

func NewSliceAndAppend[T any](slice []T, value ...T) []T

create a new slice by appending value(s) to existing slice

func NormalizeWithBasePath added in v0.3.4

func NormalizeWithBasePath(path string) string

func NormalizeWithWordkingDir added in v0.6.7

func NormalizeWithWordkingDir(path string) string

func ParseInt

func ParseInt(s string, defaultValue int) int

func SliceConcat added in v0.7.9

func SliceConcat[T any](slices ...[]T) []T

create a new slice by concatenating multiple slices

func SlicesConcat

func SlicesConcat[T any](s ...[]T) []T

func ToAnySlice

func ToAnySlice[T any](input []T) []any

Types

type FsFallback added in v0.3.0

type FsFallback struct {
	FSList []fs.FS
}

func NewFsFallback added in v0.3.0

func NewFsFallback(fses ...fs.FS) *FsFallback

Create a new FsFallback with given fs.FS list. The order of fs.FS matters: the first one has higher priority. If all fs.FS return os.ErrNotExist, the final result is os.ErrNotExist. If any fs.FS return other error, that error is returned immediately.

func (*FsFallback) AddFirstFs added in v0.3.0

func (f *FsFallback) AddFirstFs(fsys fs.FS)

adds a new fs.FS to the start of the list (highest priority)

func (*FsFallback) AddFs added in v0.3.0

func (f *FsFallback) AddFs(fsys fs.FS)

adds a new fs.FS to the end of the list (lowest priority)

func (*FsFallback) Open added in v0.3.0

func (f *FsFallback) Open(name string) (fs.File, error)

---- fs.FS ----

func (*FsFallback) ReadDir added in v0.3.0

func (f *FsFallback) ReadDir(name string) ([]fs.DirEntry, error)

---- fs.ReadDirFS ----

func (*FsFallback) Stat added in v0.3.0

func (f *FsFallback) Stat(name string) (fs.FileInfo, error)

---- fs.StatFS ----

func (*FsFallback) Sub added in v0.3.0

func (f *FsFallback) Sub(dir string) (fs.FS, error)

---- fs.SubFS ----

Jump to

Keyboard shortcuts

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