Configs2026年7月18日·1 分钟阅读

Lancet — Comprehensive Utility Function Library for Go

A reusable Go utility library providing 600+ functions covering strings, slices, maps, concurrency, cryptography, file I/O, networking, and more, all using Go generics.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Lancet Overview
直接安装命令
npx -y tokrepo@latest install 0916b73c-8243-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

Introduction

Lancet is a Go utility library inspired by JavaScript's Lodash and Java's Apache Commons. It provides a broad collection of helper functions organized into packages, covering common operations that Go developers would otherwise write repeatedly. It leverages Go generics for type-safe collection operations.

What Lancet Does

  • Provides 600+ utility functions across 30+ packages for common Go tasks
  • Covers string manipulation, slice/map operations, math, file I/O, and HTTP helpers
  • Uses Go generics for type-safe collection functions like Filter, Map, Reduce, and GroupBy
  • Includes concurrency utilities, retry logic, and rate limiting helpers
  • Offers cryptography wrappers, random generation, and validation functions

Architecture Overview

Lancet is organized as a collection of focused packages within a single module. Each package (strutil, slice, maputil, fileutil, netutil, cryptoutil, etc.) is independent and can be imported individually. Functions are designed as pure, stateless utilities with no global state. Generics-based packages require Go 1.18+. The library has zero external dependencies — every function is implemented in pure Go.

Self-Hosting & Configuration

  • Install with go get github.com/duke-git/lancet/v2 — requires Go 1.18+
  • Import only the packages you need: lancet/v2/slice, lancet/v2/strutil, etc.
  • No configuration required — all functions are stateless utilities
  • Each package can be used independently without pulling in the entire library
  • Full documentation available at pkg.go.dev with examples for every function

Key Features

  • Zero dependencies — pure Go implementation with no external packages
  • Generics support — type-safe collection operations without interface{} casting
  • Comprehensive coverage — strings, slices, maps, math, datetime, file, net, crypto, system
  • Well-tested — each function includes unit tests and benchmark tests
  • Consistent API design — predictable naming and parameter conventions across packages

Comparison with Similar Tools

  • Lodash (JS) — Lancet serves the same role for Go that Lodash serves for JavaScript
  • samber/lo — another Go generics utility library; Lancet covers more domains beyond collections
  • thoas/go-funk — pre-generics utility library using reflection; Lancet uses generics for type safety
  • standard library — Go stdlib covers basics; Lancet fills gaps like CamelCase, Chunk, and Retry

FAQ

Q: Does Lancet require Go generics? A: The v2 branch requires Go 1.18+. A v1 branch exists for older Go versions but without generics-based functions.

Q: Will importing Lancet bloat my binary? A: No, Go only compiles the packages and functions you actually import and call.

Q: How stable is the API? A: Lancet follows semantic versioning. The v2 API is considered stable with backward-compatible additions.

Q: Can I contribute new utility functions? A: Yes, the project accepts contributions. New functions should include documentation, tests, and benchmarks.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产