go-admin-core

module
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: Apache-2.0

README ยถ

go-admin-core

Go Version License

English ยท ็ฎ€ไฝ“ไธญๆ–‡ ยท ็น้ซ”ไธญๆ–‡ ยท ๆ—ฅๆœฌ่ชž

โœจ Core Features

๐Ÿ“ Logger Module (Enterprise-Grade Logging Solution)
  • Async Logger - 45x performance boost (3,358ns โ†’ 75ns), supports 100k+ QPS
  • Sampling Logger - 29x performance boost (3,357ns โ†’ 116ns), intelligent frequency control
  • Sanitizer Logger - Auto-sanitize sensitive data (phone, password, email, etc.), compliance-ready
  • Logrus Adapter - Full Logrus ecosystem support with 50+ hooks available
  • Production-Ready Config - Built-in best practices (async + sampling + sanitization)
  • Concurrency Safe - Verified with Race Detector, zero data races
๐Ÿ” JWT Authentication
  • Gin middleware - Login, refresh and identity handling for Gin applications
  • Bounded token lifetime - MaxRefresh caps how long a token may be renewed for, measured from its original issuance
  • Configurable - Timeout and MaxRefresh are both driven by configuration
๐Ÿš€ Other Components
  • Cache component (memory and Redis) โ€” see docs/storage
  • Queue component (memory and Redis streams) โ€” see docs/storage
  • Configuration management (multiple data sources)
  • Log writer (file rotation support)

Every change runs the race detector, staticcheck on two platforms, and allocation budgets on the paths that execute per request.


๐Ÿš€ Quick Start

Installation
go get -u github.com/go-admin-team/go-admin-core/v2

System Requirements: Go 1.25 or higher (see the go directive in go.mod)

Basic Logging
package main

import "github.com/go-admin-team/go-admin-core/v2/logger"

func main() {
    // Create Logrus logger instance
    log := logger.NewLogrusLogger(
        logger.WithPath("logs/app.log"),
        logger.WithLevel(logger.InfoLevel),
    )
    
    log.Log(logger.InfoLevel, "Application started")
    log.Fields(map[string]interface{}{
        "user_id": 12345,
        "action":  "login",
    }).Log(logger.InfoLevel, "User action")
}
High-Performance Async Logger
// Create async logger (recommended for high-concurrency scenarios)
baseLog := logger.NewLogrusLogger(
    logger.WithPath("logs/app.log"),
    logger.WithLevel(logger.InfoLevel),
)

asyncLog := logger.NewAsyncLogger(baseLog, logger.DefaultAsyncConfig)
defer asyncLog.(interface{ Close() error }).Close()

// 45x performance boost, only 75ns latency
asyncLog.Log(logger.InfoLevel, "High performance logging")
Sampling Logger (Frequency Control)
// Create sampling logger (auto-filter high-frequency duplicate logs)
samplingLog := logger.NewSamplingLogger(baseLog, logger.DefaultSamplingConfig)

// Only logs first 100 per second, then 1 out of every 100
for i := 0; i < 10000; i++ {
    samplingLog.Log(logger.InfoLevel, "High frequency log")
}
Sanitizer Logger (Data Security)
// Create sanitizer logger (auto-handle sensitive data)
sanitizerLog := logger.NewSanitizerLogger(baseLog, logger.DefaultSanitizerConfig)

sanitizerLog.Fields(map[string]interface{}{
    "phone":    "13812345678",  // Auto-sanitized โ†’ "138****5678"
    "password": "secret123",    // Auto-sanitized โ†’ "[REDACTED]"
    "email":    "user@example.com", // Auto-sanitized โ†’ "u***@example.com"
}).Log(logger.InfoLevel, "User login")
// Combine: Sanitizer โ†’ Sampling โ†’ Async
sanitized := logger.NewSanitizerLogger(baseLog, logger.DefaultSanitizerConfig)
sampled := logger.NewSamplingLogger(sanitized, logger.DefaultSamplingConfig)
asyncLog := logger.NewAsyncLogger(sampled, logger.DefaultAsyncConfig)
defer asyncLog.(interface{ Close() error }).Close()

// 34x performance boost + data security + frequency control
asyncLog.Fields(map[string]interface{}{
    "phone":   "13812345678",
    "user_id": 12345,
}).Log(logger.InfoLevel, "Production logging")

๐Ÿ“ฆ Configuration Management

Read Configuration Files
package main

import "github.com/go-admin-team/go-admin-core/v2/config"

func main() {
    source := config.FileSource("config.json")
    config.Setup(source, func() {
        // Configuration change callback
    })
}

๐Ÿ“Š Performance Metrics

Feature Performance Boost Latency Memory Use Case
Async Logger 45x 75ns 120 B/op High-concurrency writes
Sampling Logger 29x 116ns 16 B/op High-frequency duplicate logs
Production Config 34x 98ns 149 B/op Production environments

Test Environment: Apple M1 Pro | Go 1.25.1 | Race Detector verified


๐Ÿงช Testing

# Everything the CI gate runs
make ci

# Race detector, across every package
make test-race

# Benchmarks โ€” a smoke run; raise -benchtime for numbers worth comparing
make bench

# Sustained load, resource reclamation and goroutine lifecycles
GOADMIN_SOAK=2m make soak

# Measure this tree against a base revision, through benchstat
make bench-compare BASE=origin/main

Enforced on every change:

  • Race detector, every package
  • staticcheck for both darwin and linux
  • The exported API snapshot in api/core.txt must match the code
  • Allocation budgets on the paths that run per request
  • Downstream consumers are built against this tree

๐Ÿ“ฆ Main Dependencies

github.com/casbin/casbin/v3         v3.8.1
github.com/gin-gonic/gin            v1.11.0
github.com/golang-jwt/jwt/v5        v5.3.0
gorm.io/gorm                        v1.31.1
github.com/sirupsen/logrus          v1.9.4
golang.org/x/crypto                 v0.47.0

Versions above reflect go.mod at the time of writing; that file is the source of truth.


๐Ÿค Contributing

We welcome Issues and Pull Requests!

  1. Fork this repository
  2. Create your feature branch from main (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request against main

Branches: main is the only active branch and the source of every release. master and dev are historical and no longer accept changes โ€” master in particular has not moved since 2022 and was never part of the release lineage.

Reporting a vulnerability

Please do not open a public issue for security problems. Use private vulnerability reporting instead.


๐Ÿ“ License

Apache License 2.0 - See LICENSE file for details


  • go-admin - Gin + Vue + Element UI based RBAC system with separated frontend/backend
  • go-admin-ui - go-admin frontend project

โญ Star History

If this project helps you, please give us a Star โญ

Directories ยถ

Path Synopsis
Package config is an interface for dynamic configuration.
Package config is an interface for dynamic configuration.
encoder
Package encoder handles source encoding formats
Package encoder handles source encoding formats
loader
package loader manages loading from multiple sources
package loader manages loading from multiple sources
reader
Package reader parses change sets and provides config values
Package reader parses change sets and provides config values
source
Package source is the interface for sources
Package source is the interface for sources
source/file
Package file is a file source.
Package file is a file source.
source/memory
Package memory is a memory source
Package memory is a memory source
Package errors provides a way to return detailed information for an RPC request error.
Package errors provides a way to return detailed information for an RPC request error.
observe
sdk
api
pkg
cachetest
Package cachetest provides a black-box conformance suite for storage.Cache implementations.
Package cachetest provides a black-box conformance suite for storage.Cache implementations.
redis
Package redis implements storage.Cache and storage.Queue on top of Redis.
Package redis implements storage.Cache and storage.Queue on top of Redis.
tools
coreupgrade command
Command coreupgrade rewrites imports of the packages this module deprecated in v1.6.0 to the paths that replace them in v2.0.0.
Command coreupgrade rewrites imports of the packages this module deprecated in v1.6.0 to the paths that replace them in v2.0.0.

Jump to

Keyboard shortcuts

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