idrm_go_frame

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

README

idrm-go-frame

中文说明

A Go foundation framework for backend services, with app lifecycle, config, logging, transport, registry, storage, and utility modules.

Overview

idrm-go-frame focuses on reusable building blocks for services: lifecycle management, configuration, logging, HTTP/Kafka transport, registry/discovery, storage helpers, and common utilities.

Features

  • Application lifecycle (start/stop, graceful shutdown, service registration).
  • Configuration (multi-source, multi-format, hot reload).
  • Logging (zap-based, multi-output, multi-level).
  • Transport: REST (Gin) and Kafka (kafkax / kq).
  • Telemetry wrappers for logs and tracing.
  • Storage/cache utilities: gormx, redis tools, distributed locks.
  • Common utilities: enum, encoding, syncx, utils.

Layout

  • app.go: application lifecycle and runner.
  • core/config: configuration loaders and parsers.
  • core/logx: logging infrastructure.
  • core/transport/rest: REST server wrapper (Gin).
  • core/transport/mq/kafkax: Kafka consumer/producer wrappers.
  • core/telemetry: logging and tracing components.
  • core/store / core/redis_tool: storage/cache helpers.
  • docs/: component docs and examples.

Quick Start

package main

import (
	"log"

	"github.com/gin-gonic/gin"
	idrm "github.com/kweaver-ai/idrm-go-frame"
	"github.com/kweaver-ai/idrm-go-frame/core/transport/rest"
)

func main() {
	r := gin.Default()
	r.GET("/healthz", func(c *gin.Context) { c.String(200, "ok") })

	srv := rest.NewServer(r, rest.Address(":8080"))
	app := idrm.New(idrm.Name("demo"), idrm.Server(srv))

	if err := app.Run(); err != nil {
		log.Fatalf("app run error: %v", err)
	}
}

Docs

  • Config: docs/component/config.md
  • Logging: docs/component/logger.md
  • Enum: docs/component/enum.md
  • Kafka: docs/transport/kafkax.md

Requirements

  • Go version: go 1.24 (from go.mod)
  • Key deps: Gin, Kratos, Zap, GORM, Kafka, OpenTelemetry, etc.

License

No license is specified in this repository.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContext

func NewContext(ctx context.Context, s AppInfo) context.Context

NewContext returns a new Context that carries value.

Types

type App

type App struct {
	// contains filtered or unexported fields
}

func New

func New(opts ...Option) *App

New create an application lifecycle manager.

func (*App) Endpoint

func (a *App) Endpoint() []string

Endpoint returns endpoints.

func (*App) ID

func (a *App) ID() string

func (*App) Name

func (a *App) Name() string

func (*App) Run

func (a *App) Run() error

Run executes all OnStart hooks registered with the application's Lifecycle.

func (*App) Stop

func (a *App) Stop() error

Stop gracefully stops the application.

type AppInfo

type AppInfo interface {
	ID() string
	Name() string
	//Version() string
	//Metadata() map[string]string
	Endpoint() []string
}

AppInfo is application context value.

func FromContext

func FromContext(ctx context.Context) (s AppInfo, ok bool)

FromContext returns the Transport value stored in ctx, if any.

type Application

type Application struct {
	Name     string
	Version  string
	Addr     string
	ConfPath string
}

type Option

type Option func(o *options)

func Context

func Context(ctx context.Context) Option

Context with service context.

func Endpoint

func Endpoint(endpoints ...*url.URL) Option

Endpoint with service endpoint.

func ID

func ID(id string) Option

ID 设置Server的ID

func Logger

func Logger(logger log.Logger) Option

Logger with service logger.

func Name

func Name(name string) Option

Name 设置Server的Name

func Registrar

func Registrar(r registry.Registrar) Option

Registrar with service registry.

func RegistrarTimeout

func RegistrarTimeout(t time.Duration) Option

RegistrarTimeout with registrar timeout.

func Server

func Server(srv ...transport.Server) Option

Server with transport servers.

func Signal

func Signal(sigs ...os.Signal) Option

Signal with exit signals.

func StopTimeout

func StopTimeout(t time.Duration) Option

StopTimeout with app stop timeout.

Jump to

Keyboard shortcuts

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