用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/Goldziher/go-utils --skill usage-patterns-and-examples命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| description | usage-patterns-and-examples |
| name | usage-patterns-and-examples |
| user_invocable | false |
go get -u github.com/Goldziher/go-utils
The sliceutils package provides familiar operations for developers coming from JavaScript:
import "github.com/Goldziher/go-utils/sliceutils"
// Filter and Map (chainable pattern)
numbers := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
filtered := sliceutils.Filter(numbers, func(val int, idx int, slice []int) bool {
return val%2 == 0
}) // [2, 4, 6, 8, 10]
doubled := sliceutils.Map(filtered, func(val int, idx int, slice []int) int {
return val * 2
}) // [4, 8, 12, 16, 20]
// Reduce for aggregation
sum := sliceutils.Reduce(numbers, func(acc int, cur int, idx int, slice []int) int {
return acc + cur
}, 0) // 55
// Set operations
a := []int{1, 2, 3, 4}
b := []int{3, 4, 5, 6}
union := sliceutils.Union(a, b) // [1, 2, 3, 4, 5, 6]
intersection := sliceutils.Intersection(a, b) // [3, 4]
difference := sliceutils.Difference(a, b) // [1, 2, 5, 6]
import "github.com/Goldziher/go-utils/maputils"
data := map[string]int{"a": 1, "b": 2, "c": 3}
// Extract keys and values
keys := maputils.Keys(data) // ["a", "b", "c"]
values := maputils.Values(data) // [1, 2, 3]
// Filter map entries
filtered := maputils.Filter(data, func(key string, value int) bool {
return value > 1
}) // {"b": 2, "c": 3}
// Merge maps (right-to-left precedence)
m1 := map[string]int{"a": 1, "b": 2}
m2 := map[string]int{"b": 3, "c": 4}
merged := maputils.Merge(m1, m2) // {"a": 1, "b": 3, "c": 4}
import "github.com/Goldziher/go-utils/structutils"
type User struct {
Name string `json:"name"`
Age int `json:"age"`
Email string `json:"email"`
}
user := User{Name: "Alice", Age: 30, Email: "alice@example.com"}
// Convert struct to map (respects struct tags)
userMap := structutils.ToMap(user, "json")
// {"name": "Alice", "age": 30, "email": "alice@example.com"}
import "github.com/Goldziher/go-utils/urlutils"
// From map
params := map[string]any{
"search": "golang",
"page": 1,
"tags": []string{"generics", "utils"},
}
query := urlutils.QueryStringifyMap(params)
// "page=1&search=golang&tags=generics&tags=utils"
// From struct
type QueryParams struct {
Search string `qs:"q"`
Page int `qs:"page"`
Tags []string `qs:"tag"`
}
params := QueryParams{Search: "golang", Page: 1, Tags: []string{"generics", "utils"}}
query := urlutils.QueryStringifyStruct(params, "qs")
// "page=1&q=golang&tag=generics&tag=utils"
All functions provide compile-time type safety:
// Compile error: type mismatch
numbers := []int{1, 2, 3}
result := sliceutils.Map(numbers, func(val int, idx int, slice []int) string {
return strconv.Itoa(val) // Returns []string, not []int
})