utils

package
v1.3.14 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	COUNTER2_A = 1<<iota + 2
	COUNTER2_B
	COUNTER2_C
	COUNTER2_D
)
View Source
const CHARSET = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

Variables

This section is empty.

Functions

func CreateFile added in v1.1.0

func CreateFile(absPath string, payload io.Reader, opts ...FileOptionFunc) error

CreateFile is an alias for WriteFile.

func CreateIfNotExist added in v1.0.1

func CreateIfNotExist(path string, defaultValue string) error

CreateIfNotExist checks if a file exists at the given path. If the file does not exist, it creates one with the provided defaultValue. It supports "~" as the home directory.

func FileExists added in v1.0.1

func FileExists(fpath string) bool

func GetFileName added in v1.0.1

func GetFileName(fpath string) string

func Int32Pointer

func Int32Pointer(i int32) *int32

func Int64Pointer

func Int64Pointer(i int64) *int64

func IntPointer

func IntPointer(i int) *int

func IsNil

func IsNil(p any) bool

func LoadCSV added in v1.1.0

func LoadCSV[T any](inputPath string) ([]T, error)

LoadCSV 是一個泛型函數,能將 CSV 檔案直接解析為任意指定結構體 (Structure) 的切片 (Slice)

func NewCSVFilelistCallback added in v1.0.1

func NewCSVFilelistCallback(pattern string, rowProcessor sdkcsv.RecordProcessor) error

func NewFileOpenCallback added in v1.0.1

func NewFileOpenCallback(fpath string, fn func(f *os.File) error) error

func NewFilelistCallback added in v1.0.1

func NewFilelistCallback(pattern string, f FileCallback) error

func OpenFile added in v1.1.0

func OpenFile(absPath string, opts ...FileOptionFunc) (*os.File, error)

OpenFile opens or creates a file at absPath according to provided options.

func ParseCSVFile added in v1.0.1

func ParseCSVFile(fpath string) (*csv.Reader, *os.File, error)

func ParseTimeDuration added in v1.0.1

func ParseTimeDuration(s string) (time.Duration, error)

ParseHHMMSS converts a string of "HH:MM:SS" format to a time.Duration.

func ResolvePath deprecated added in v1.1.0

func ResolvePath(path string) (string, error)

Deprecated: use github.com/mitchellh/go-homedir or similar specialized package instead.

func SaveFile deprecated added in v1.0.1

func SaveFile(absPath string, payload io.Reader) error

Deprecated: use WriteFile instead.

func String

func String(length int) string

func StringPointer

func StringPointer(s string) *string

func StringWithCharset

func StringWithCharset(length int, charset string) string

func Uint32Pointer

func Uint32Pointer(i uint32) *uint32

func Uint64Pointer

func Uint64Pointer(i uint64) *uint64

func UintPointer

func UintPointer(i uint) *uint

func WriteCSV added in v1.1.0

func WriteCSV(absPath string, data any) error

WriteCSV writes data (either [][]string or a slice of structs) to a CSV file. If data is [][]string, it writes the raw rows using standard encoding/csv. Otherwise, it marshals the struct slice using gocsv.

func WriteFile added in v1.1.0

func WriteFile(absPath string, payload io.Reader, opts ...FileOptionFunc) error

WriteFile writes payload to absPath according to provided options. Default behavior is to fail if file doesn't exist, and override if it does.

Types

type FileCallback added in v1.0.1

type FileCallback func(string) error

type FileOptionFunc added in v1.1.0

type FileOptionFunc func(*FileOptions)

FileOptionFunc defines configuration builder for CreateFile.

func WithBackup added in v1.1.0

func WithBackup() FileOptionFunc

WithBackup enables recursive backup of existing files.

func WithCreate added in v1.1.0

func WithCreate() FileOptionFunc

WithCreate enables file creation if it doesn't exist.

func WithReturnWriter added in v1.1.0

func WithReturnWriter(w *io.Writer) FileOptionFunc

WithWriter allows retrieving the opened writer.

type FileOptions added in v1.1.0

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

type SampleInt added in v1.1.0

type SampleInt int
const (
	COUNTER_A SampleInt = iota + 100 // 111111
	COUNTER_B                        // 222222
	COUNTER_C                        // 333333
	COUNTER_D                        // 444444
)

123123sjdasio

type SampleInt2 added in v1.1.0

type SampleInt2 int
const (
	COUNTER1_A SampleInt2 = iota
	COUNTER1_B
	COUNTER1_C
	COUNTER1_D
	COUNTER1_E
	COUNTER1_F
	COUNTER1_G
	COUNTER1_H
	COUNTER1_I
	COUNTER1_J
	COUNTER1_K
	COUNTER1_L
	COUNTER1_M
)

Jump to

Keyboard shortcuts

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