appkit

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 1 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-app-kit

Shared HTTP application kit for Gin services (context envelope, middleware, bootstrap, logging, field encryption).

Packages: def (constants), core (request context), errcode, middleware, bootstrap, config, logging, telemetry, singleflight, fieldcrypt; root appkit defines Module / Closer.

Install

go get github.com/andywang2011/go-app-kit@v0.1.0

Quick start

gin.SetMode(gin.TestMode)
r := gin.New()
r.Use(kitmw.Recovery)
r.GET("/ping", core.Handle(func(c *core.Context) {
	c.Success(gin.H{"ok": true})
}))

w := httptest.NewRecorder()
req := httptest.NewRequest("GET", "/ping", nil)
r.ServeHTTP(w, req)
fmt.Println(w.Code)

Examples

cd examples
go run .

License

MIT — see LICENSE.

Documentation

Overview

Package appkit is the root of go-app-kit, a shared HTTP application kit that extracts the common web-server plumbing used by multiple Gin-based services (request Context, response envelope, error codes, middleware, process bootstrap, logging/telemetry helpers and field encryption).

Design constraints

  • No global singletons: callers construct dependencies and pass Config structs; middleware and helpers accept their dependencies explicitly.
  • ConfigDefault: N/A at package root; subpackages (e.g. telemetry) expose ConfigDefault where applicable.
  • No log.Fatal / os.Exit inside library code: failures are returned as errors so the caller decides how to react.
  • Business logic stays out of the kit: it never imports caller business packages (controller/service/repository/model). The kit exposes framework primitives only; callers compose them into their own layering.
  • Context propagation: per-request work flows through core.Context, which embeds *gin.Context so handlers keep full Gin access.

Known exceptions (documented, intentional)

  • gin dependency: this is an HTTP application kit, not a pure SDK, so it intentionally depends on github.com/gin-gonic/gin. core.Context embeds *gin.Context and middleware are Gin handlers.
  • viper in bootstrap/ and config/: the bootstrap and config packages may use github.com/spf13/viper for optional Load* helpers and process startup (loading conf.yaml, APP_* env overrides, Nacos sync). This mirrors the documented go-nacos env exception: it is confined to process startup and is never used by the request-path packages (core, errcode, middleware).

Packages

  • def framework constants (env names, language codes, header keys)
  • core request Context, Handle decorator, response envelope, Subject
  • errcode ErrCode type plus shared Lib*/Web* error codes
  • middleware reusable Gin middleware (recovery, logging, cors, ...)
  • bootstrap process startup: viper + optional Nacos sync + secret checks
  • config pure config structs and viper Load helpers (no service deps)
  • logging process-level logging setup helpers
  • telemetry optional tracing/metrics bootstrap helpers
  • singleflight in-process request de-duplication
  • fieldcrypt field-level encryption / masking / normalization helpers
Example (Middleware)
package main

import (
	"fmt"
	"net/http/httptest"

	"github.com/andywang2011/go-app-kit/core"
	kitmw "github.com/andywang2011/go-app-kit/middleware"
	"github.com/gin-gonic/gin"
)

func main() {
	gin.SetMode(gin.TestMode)
	r := gin.New()
	r.Use(kitmw.Recovery)
	r.GET("/ping", core.Handle(func(c *core.Context) {
		c.Success(gin.H{"ok": true})
	}))

	w := httptest.NewRecorder()
	req := httptest.NewRequest("GET", "/ping", nil)
	r.ServeHTTP(w, req)
	fmt.Println(w.Code)
}
Output:
200

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Closer

type Closer interface {
	// Close releases the component's resources, returning the first error.
	Close() error
}

Closer is implemented by components that hold resources (connections, async writers, background goroutines) which must be released on shutdown.

Close must be safe to call once; implementations should make it idempotent where practical. The process shutdown sequence calls Close on every Closer.

type Module

type Module interface {
	// Name returns a stable identifier used for logging and diagnostics.
	Name() string
	// Enabled reports whether the module should be registered. A disabled
	// module is skipped entirely (no routes, no background work).
	Enabled() bool
	// Register mounts the module's routes onto the provided router group.
	Register(r *gin.RouterGroup)
}

Module is a self-contained feature that registers its routes onto a Gin router group. A process composes several Modules behind its router.

Implementations must be safe to call Register once during startup.

Directories

Path Synopsis
Package bootstrap performs process startup before Wire: it optionally syncs remote Nacos configuration, loads the local conf.yaml into viper, applies APP_* environment overrides and validates app.env and production secrets.
Package bootstrap performs process startup before Wire: it optionally syncs remote Nacos configuration, loads the local conf.yaml into viper, applies APP_* environment overrides and validates app.env and production secrets.
Package config holds pure, reusable application configuration structs and their viper Load helpers.
Package config holds pure, reusable application configuration structs and their viper Load helpers.
Package core provides the per-request Context used by handlers built on the kit, the Handle decorator that adapts handlers to Gin, and the JSON response envelope (Success / Fail / FailWithErrCode).
Package core provides the per-request Context used by handlers built on the kit, the Handle decorator that adapts handlers to Gin, and the JSON response envelope (Success / Fail / FailWithErrCode).
Package def holds framework-level constants shared by the HTTP kit: environment names, language codes and well-known request header keys.
Package def holds framework-level constants shared by the HTTP kit: environment names, language codes and well-known request header keys.
Package errcode defines the ErrCode value type carried across the HTTP kit and the framework/web error codes shared by every service built on the kit.
Package errcode defines the ErrCode value type carried across the HTTP kit and the framework/web error codes shared by every service built on the kit.
Package middleware provides reusable Gin middleware for services built on the kit: panic recovery, request logging, CORS, security headers, rate limiting, IP whitelisting, raw-body caching, request id/time-zone setup, Prometheus RED metrics and core dependency injection.
Package middleware provides reusable Gin middleware for services built on the kit: panic recovery, request logging, CORS, security headers, rate limiting, IP whitelisting, raw-body caching, request id/time-zone setup, Prometheus RED metrics and core dependency injection.
Package singleflight provides in-process duplicate call suppression.
Package singleflight provides in-process duplicate call suppression.

Jump to

Keyboard shortcuts

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