utils

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Address

func Address(col int, row int) string

*

  • @param col 要转换的数字
  • @param row 要转换的数字
  • @return 转换后的结果

func ClearRows

func ClearRows(wb *excelize.File, sheet string, start int, end int)

*

  • @param wb Excel文件对象
  • @param sheet 工作表名称
  • @param start 起始行索引
  • @param end 结束行索引

func ColToInt

func ColToInt(colName string) int

*

  • @param colName 要转换的列名
  • @return 转换后的结果

func CopyRowsBetween

func CopyRowsBetween(wb *excelize.File, sheet string, start int, end int)

*

  • @param wb Excel文件对象
  • @param sheet 工作表名称
  • @param start 起始行索引
  • @param end 结束行索引

func Decode

func Decode(input interface{}, result interface{}) error

func Dir

func Dir(names ...string) *paths.Path

Dir 根据传入的目录名称依次在当前工作目录下创建目录,并返回最终目录的路径。 参数 names 为要创建的目录名称列表(可变参数)。 返回值为最终创建的目录的 *paths.Path 对象。

func GetIPs

func GetIPs(includeLocalhost bool) []string

GetIPs returns a slice of IP addresses of the local machine. If includeLocalhost is true, it also includes "localhost" in the result. It filters out loopback addresses and only includes IPv4 addresses. Note: This function does not handle errors from net.InterfaceAddrs(). It is assumed that the caller will handle any potential errors. The function is useful for logging or displaying server addresses.

func HeaderIndexByKeywords

func HeaderIndexByKeywords(rows [][]string, keywords []string) (int, []string, error)

*

  • @param rows 二维字符串数组,每一行表示Excel中的一行数据
  • @param keywords 关键词数组,用于确定标题行的位置
  • @return 标题行索引、标题行数据、错误信息

func IntToCol

func IntToCol(index int) string

*

  • @param index 要转换的数字
  • @return 转换后的结果

func LogServer

func LogServer(https bool, port int)

LogServer prints the server address in a formatted way. It takes a boolean indicating whether to use HTTPS and an integer for the port.

func LogServerWithBasePath added in v0.1.5

func LogServerWithBasePath(https bool, port int, basePath string)

LogServerWithBasePath prints Local/Network URLs with a styled format.

func LogServerWithQR added in v0.0.3

func LogServerWithQR(https bool, port int, includeLocalhost bool)

LogServerWithQR prints the server address and renders a QR code in terminal. It will prioritize the first non-localhost URL for QR, fallback to localhost.

func LogServerWithQRAndBasePath added in v0.1.5

func LogServerWithQRAndBasePath(https bool, port int, includeLocalhost bool, basePath string)

LogServerWithQRAndBasePath prints Local/Network URLs and renders QR code.

func MultipleFiles

func MultipleFiles(c *gin.Context) []string

func MultipleFilesWithTimestamp

func MultipleFilesWithTimestamp(c *gin.Context) []string

func NewUUID added in v0.0.3

func NewUUID() string

NewUUID returns a RFC 4122 UUID string.

func NewXID added in v0.0.3

func NewXID() string

NewXID returns a lexicographically sortable XID string.

func ParseAddress

func ParseAddress(address string) (int, int, error)

*

  • @param address 要解析的地址
  • @return 解析后的结果

func ParseDecimal added in v0.0.3

func ParseDecimal(value string) (decimal.Decimal, error)

ParseDecimal parses a decimal string.

func ParseDecimalOrZero added in v0.0.3

func ParseDecimalOrZero(value string) decimal.Decimal

ParseDecimalOrZero parses a decimal string and returns zero on error.

func ParseTimeAny added in v0.0.3

func ParseTimeAny(value string) (time.Time, error)

ParseTimeAny parses a date/time string with dateparse.

func ParseUUID added in v0.0.3

func ParseUUID(value string) (uuid.UUID, error)

ParseUUID validates and parses a UUID string.

func Percentage

func Percentage(value float32, min float32, max float32) (raw float32, safe float32)

获取百分比, 结果为0-100之间的值

func Print added in v0.1.4

func Print(v ...any)

Print prints a single log line with a green [go] prefix.

func PrintMulti added in v0.1.4

func PrintMulti(lines ...string)

PrintMulti prints multiple lines, each prefixed with a green [go] tag.

func ReadFirstSheetRaw

func ReadFirstSheetRaw(path string) ([][]string, error)

*

  • @param path Excel文件路径
  • @return 转换后的字符串字典数组

func SetServerLogStyle added in v0.1.5

func SetServerLogStyle(style ServerLogStyle)

SetServerLogStyle changes LogServer output color theme.

func ToTimeHookFunc

func ToTimeHookFunc() mapstructure.DecodeHookFunc

func TryFindMatch

func TryFindMatch(pattern string, stringToMatch string) (*re.Match, error)

func ValidateStruct added in v0.0.3

func ValidateStruct(value interface{}) error

ValidateStruct validates a struct using a new validator instance.

func ValidateVar added in v0.0.3

func ValidateVar(value interface{}, tag string) error

ValidateVar validates a variable against a tag using a new validator instance.

func Validator added in v0.0.3

func Validator() *validator.Validate

Validator returns a default validator instance.

func Write1

func Write1[DataType any](wb *excelize.File, sheet string, colIndex int, rowIndex int, values [][]DataType) []error

*

  • @param wb Excel文件对象
  • @param sheet 工作表名称
  • @param colIndex 列索引
  • @param rowIndex 行索引
  • @param values 要写入的值
  • @return 错误数组

func Write2

func Write2[DataType any](wb *excelize.File, sheet string, colName string, rowIndex int, values [][]DataType) []error

*

  • @param wb Excel文件对象
  • @param sheet 工作表名称
  • @param colName 列名
  • @param rowIndex 行索引
  • @param values 要写入的值
  • @return 错误数组

Types

type ServerLogStyle added in v0.1.5

type ServerLogStyle string

ServerLogStyle controls the color theme of LogServer output.

const (
	// ServerLogStyleNeon keeps the current bright green/magenta/cyan style.
	ServerLogStyleNeon ServerLogStyle = "neon"
	// ServerLogStyleSunset uses a warm orange/yellow palette.
	ServerLogStyleSunset ServerLogStyle = "sunset"
	// ServerLogStyleOcean uses cool blue/cyan tones.
	ServerLogStyleOcean ServerLogStyle = "ocean"
	// ServerLogStyleForest uses green/yellow tones.
	ServerLogStyleForest ServerLogStyle = "forest"
	// ServerLogStyleMono uses grayscale output.
	ServerLogStyleMono ServerLogStyle = "mono"
)

func ServerLogStyles added in v0.1.6

func ServerLogStyles() []ServerLogStyle

ServerLogStyles returns all available styles.

type StringDict

type StringDict map[string]string

func ReadFirstSheet1

func ReadFirstSheet1(path string, headerIndex int, dataIndex int) ([](StringDict), error)

*

  • @param path Excel文件路径
  • @param headerIndex 标题行索引
  • @param dataIndex 数据行索引
  • @return 转换后的字符串字典数组

func ReadFirstSheet2

func ReadFirstSheet2(path string, colNameExamples []string, dataIndexOffset int) ([](StringDict), error)

*

  • @param path Excel文件路径
  • @param colNameExamples 列名示例,用于确定标题行的位置
  • @param dataIndexOffset 数据行索引的偏移量,用于确定数据行的位置
  • @return 转换后的字符串字典数组

func RowsToDict1

func RowsToDict1(rows [][]string, headerIndex int, dataIndex int) [](StringDict)

*

  • @param rows 二维字符串数组,每一行表示Excel中的一行数据
  • @param headerIndex 标题行索引
  • @param dataIndex 数据行索引
  • @return 转换后的字符串字典数组

func RowsToDict2

func RowsToDict2(rows [][]string, colNameExamples []string, dataIndexOffset int) ([](StringDict), error)

*

@param rows 二维字符串数组,每一行表示Excel中的一行数据
@param colNameExamples 列名示例,用于确定标题行的位置
@param dataIndexOffset 数据行索引的偏移量,用于确定数据行的位置
@return 转换后的字符串字典数组

Jump to

Keyboard shortcuts

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