knife

command module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: MIT Imports: 2 Imported by: 0

README

knife

Go Report Card Go Version CI

A comprehensive Go utility library providing common tools and abstractions for building production-ready applications.

Features

knife is a collection of well-tested, reusable Go packages organized into the following categories:

Database
  • ORM Abstractions - Unified database interface supporting MySQL, PostgreSQL, Oracle, SQLite, and SQL Server
  • Criteria Builder - Fluent query building with type safety
  • Naming Strategies - Configurable naming conventions for database entities
Caching & Storage
  • Redis Integration - High-level Redis client with HA support
  • Cache Abstractions - Generic cache interfaces for flexibility
Observability
  • OpenTelemetry Integration - Tracing, metrics, and logging out of the box
  • Structured Logging - Built on log/slog with OTel bridges
  • Elasticsearch Client - Typed search abstractions for complex queries
Utilities
  • Serialization - Generic JSON/YAML (de)serialization with Go generics
  • Expression Evaluation - Safe runtime expression evaluation
  • Internationalization - i18n support with message templates
  • Maps & Lists - Enhanced collection utilities
  • Time Utilities - Timezone-aware formatting and conversion
  • Type Definitions - Common domain types and converters
Integration
  • Kubernetes Helpers - Service account and secret access
  • Nacos Client - Service discovery and configuration management
  • Authentication - JWT and auth utilities

Installation

go get github.com/gantries/knife@latest

Quick Start

Database ORM
import "github.com/gantries/knife/pkg/orm"

// Configure database connection
db := orm.New(orm.Properties{
    Dialect:      types.Postgres,
    DSN:          "host=localhost user=gorm password=gorm dbname=gorm port=9920 sslmode=disable",
    TablePrefix:  "app_",
    SingularTable: true,
})

// Use with GORM
db.DB().AutoMigrate(&User{})
Caching
import "github.com/gantries/knife/pkg/cache"

// Create Redis cache
cache := cache.New(cache.Properties{
    Addr:     "localhost:6379",
    Password: "",
    DB:       0,
})

// Set and get values
cache.Set(ctx, "key", "value", time.Hour)
value, err := cache.Get(ctx, "key")
Serialization
import "github.com/gantries/knife/pkg/serde"

// Serialize/Deserialize with generics
data, err := serde.Serialize(user)
user, err := serde.Deserialize[User](data)

// YAML support
data, err := serde.SerializeYAML(config)
config, err := serde.DeserializeYAML[Config](data)
Expression Evaluation
import "github.com/gantries/knife/pkg/eval"

program, err := eval.Compile("user.Age > 18 && user.Active == true")
result, err := program.Eval(map[string]any{
    "user": map[string]any{"Age": 25, "Active": true},
})
// result: true
OpenTelemetry
import "github.com/gantries/knife/pkg/tel"

// Setup tracing
tp, err := tel.SetupTracer("my-service", "localhost:4317")
defer tel.ShutdownTracer(context.Background(), tp)

// Setup metrics
mp, err := tel.SetupMeter("my-service", "localhost:4317")
defer tel.ShutdownMeterProvider(context.Background(), mp)

// Setup logging
tel.SetupLoggersCreated(lp)
logger := tel.Logger("my-app")
Time Utilities
import "github.com/gantries/knife/pkg/times"

// Format timestamp
formatted := times.FormatTs(1731542400000)
// Output: "2024-11-14 00:00:00" (local timezone)

// Format with custom layout
formatted := times.FormatTsByLayout(1731542400000, "2006/01/02")
// Output: "2024/11/14"

Documentation

For detailed documentation, see:

Project Status

knife is actively maintained and used in production environments. The library follows semantic versioning and aims for backward compatibility within major versions.

Development

Prerequisites
  • Go 1.21 or later
Running Tests
# Run all tests
go test ./...

# Run tests with coverage
go test -cover ./...

# Run tests with race detection
go test -race ./...
Building
# Build all packages
go build ./...

Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Acknowledgments


Made with ❤️ by the knife contributors

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
pkg
assert
Package assert provides simple assertion utilities for testing.
Package assert provides simple assertion utilities for testing.
dot
Package dot contains utilities can be used extreme frequently.
Package dot contains utilities can be used extreme frequently.
env
errors
Package errors provides internationalized error definitions and utilities.
Package errors provides internationalized error definitions and utilities.
fs
Package fs contains file iostream related utilities
Package fs contains file iostream related utilities
ha
Package ha provides high-availability (HA) execution patterns.
Package ha provides high-availability (HA) execution patterns.
kube
Package kube provides utilities for reading Kubernetes service account secrets.
Package kube provides utilities for reading Kubernetes service account secrets.
lang
Package lang contains all language level utilities.
Package lang contains all language level utilities.
log
Package log provides a simple logging facade built on top of the tel package.
Package log provides a simple logging facade built on top of the tel package.
maps
Package maps provides map-based data structures and utilities.
Package maps provides map-based data structures and utilities.
nacos
Package nacos contains nacos config service utility.
Package nacos contains nacos config service utility.
num
orm
orm/mysql
Package mysql contains mysql dialect factory.
Package mysql contains mysql dialect factory.
orm/oracle
Package oracle contains oracle dialect factory.
Package oracle contains oracle dialect factory.
orm/postgres
Package postgres contains postgres dialect factory.
Package postgres contains postgres dialect factory.
orm/sqlite
Package sqlite contains sqlite dialect factory.
Package sqlite contains sqlite dialect factory.
orm/sqlserver
Package sqlserver contains sqlserver dialect factory.
Package sqlserver contains sqlserver dialect factory.
serde
Package serde provides serialization and deserialization utilities.
Package serde provides serialization and deserialization utilities.
synch
Package synch provides synchronization primitives.
Package synch provides synchronization primitives.
tel
Package tel provides OpenTelemetry integration for observability.
Package tel provides OpenTelemetry integration for observability.
times
Package times provides time formatting and timezone utilities.
Package times provides time formatting and timezone utilities.
types
Package types contains all types definition for gqlgin/gorm
Package types contains all types definition for gqlgin/gorm
ver
Package ver provides version information for the application.
Package ver provides version information for the application.

Jump to

Keyboard shortcuts

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