百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
C

cyan

> 编程语言
开源

一个现代、全面且高效的 Go 实用程序库。

200 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

一个现代、全面且高效的 Go 实用程序库。

Synopsis

A modern, comprehensive and efficient utility library of Golang.

Features

  • Comprehensive, efficient and reusable.
  • Numerous utility functions, support string, slice, map, datetime, crypto...
  • Only depend on the go standard and golang.org/x library.
  • High unit test coverage for exported functions.

Encoding

Some utility functions can be used to handle conversion of different character encoding, such as gbk to utf8.

go
gbk := []byte{0xC4, 0xE3, 0xBA, 0xC3}   // 你好 in gbk
GbkToUtf8(gbk)                          // 你好 in utf8
Utf8ToGbk(utf8)                         // [196 227 186 195]

Some converting function to json.

go
student := struct {
    Hobby   string
    Age     int32
}{
    Hobby: "pingpopng",
    Age:   28,
}
encoding.ToIndentJSON(&student)
/*
output:
{
    "Hobby": "pingpopng",
    "Age": 28
}
*/

Net

Some utility functions can be used to handle network. For example you can use IPv4StrToU32() transform ipv4 string to uint32 value.

go
IsReservedIP("0.0.0.256")    // -1 invalid ip
IsReservedIP("39.156.69.79") // 0 public ip
IsReservedIP("127.0.0.1")    // 1 reserved ip

IPv4StrToU32("127.0.0.1")      // 2130706433
U32ToIPv4Str(2130706433)       // "127.0.0.1"
GetNativeEndian()              // LittleEndian
IsLittleEndian()               // true

Slice

Some useful utility functions can be used to handle slice.

…

String

Some utility functions can be used to handle string.

go
Split("a,b,c", ",")                    // []string{"a", "b", "c"}
SplitSeps("a,b|c", ",", "|")           // []string{"a", "b", "c"}
SplitSeps("a,bSEPc", ",", "SEP")       // []string{"a", "b", "c"}

Join([]int{1, 2, 3}, ",")              // "1,2,3"
Join([]string{"a", "", "b"}, ",")      // "a,,b"
JoinNonEmptyStrs(",", "a", "", "b")    // "a,b"

Reverse("abc")                         // "cba"

AlphanumericNum("108条梁山man")         // 6
AlphanumericNumV2("108条梁山man")       // 6
AlphanumericNumRegExp("108条梁山man")   // 6

Time

Some utility functions can be used to handle date and time.

…

Type Conversion

Some utility functions can be used to convert one type to another type.

to basic types

…

to set

go
// Convert bool slice or array to set.
bools := []bool{true, false, true}
ToSet[bool](bools)
ToSetE[bool](bools)

// Convert int slice or array to set.
ints := []int{1, 2, 3}
ToSet[int](ints)
ToSetE[int](ints)

// Convert string slice or array to set.
strs := []string{"foo", "bar", "baz"}
ToSet[string](strs)
ToSetE[string](strs)

// Split string to set.
SplitStrToSet("a,b,c", ",")  // map[a:{}, b:{}, c:{}]

to slice

…

to map

go
var st = struct {
    I int
    S string
}{I: 1, S: "a"}

// to map[string]any
StructToMap(st)         // map["I":1 "S":"a"]
StructToMapStr(st)      // map["I":"1" "S":"a"]

// json or other type to map[string]string
ToMapStr(`{"foo":"foo","bar":"bar","baz":"baz"}`)  // map["foo":"foo" "bar":"bar" "baz":"baz"]
ToMapStrE(`{"foo":"foo","bar":"bar","baz":"baz"}`) // map["foo":"foo" "bar":"bar" "baz":"baz"], nil

URL

Some utility functions can be used to handle URL.

…

Crypto

Some utility functions can be used to create Hash, HMAC and crypt data.

…

Rand

Some utility functions to create a real non-negative random int number, specified length random string and so on.

go
GetRandInt()               // 2040723487295132865
GetRandIntn(100)           // 49
GetRandIntRange(0, 100)    // 44
GetRandByteSlice(3)        // [241 16 101]
GetRandStr(3)              // dAt
GetRandLowerStr(3)         // lts
GetRandUpperStr(3)         // YUT

File

Some utility functions to operate on the file.

go
// List contents of the directory.
ListDir()
ListFileNames()
ListDirEntryPaths()
ListDirEntryPathsSymlink()

// Check the file or directory.
IsExist()
IsDir()
IsDirE()
IsFile()
IsFileE()
IsSymlink()
IsSymlinkE()
IsShortcutFile()

// Create a file.
Create()
CreateFile()

// Clears a file content.
ClearFile()

// Gets file info.
FileMd5()
FileMd5Reader()
FileSize()
FileSizeFile()

// and so on.

Comparison

Some utility functions to handle comparison.

go
// Compare two any type value.
Cmp(888, 889)       // LT
Cmp(888, 888)       // EQ
Cmp(889, 888)       // GT
Cmp(88.8, 88.9)     // LT
Cmp(88.8, 88.8)     // EQ
Cmp(88.9, 88.8)     // GT
Cmp("abc", "b")     // LT
Cmp("abc", "abc")   // EQ
Cmp("b", "abc")     // GT

// Compare semantic version. 
b, _ := VerGTVer("1.0.5", "1.0.4")   // true
b, _ := VerLTVer("1.0.5", "2.0.4")   // true
b, _ := VerGEVer("2.0.4", "2.0.4")   // true
b, _ := VerLEVer("1.0.5", "1.0.5")   // true

Others

Some utility functions now unclassified. Of course, it may be classified and moved to a new subdirectory in the future.

go
// NO NOW.

How to Contribute

We really appreciate any code commits which make this lib powerful. Please follow the rules below to create your pull request.

  1. Fork the repository.
  2. Add and Commit your changes.
  3. Push to your forked repository.
  4. Create new pull request.

Summary

The above examples are just the tip of the iceberg. For more usage, please read the source code.

Due to the limited personal ability, you are welcome to criticize and correct. Of course, welcome to join in the construction of this library.

Star History

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Go

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言