-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoc.go
More file actions
118 lines (118 loc) · 3.61 KB
/
doc.go
File metadata and controls
118 lines (118 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Package go-webmods provides a collection of common web application components
// for Go services. It follows a modular plugin architecture where each package
// provides factory functions and config-driven initialization.
//
// # Overview
//
// This library includes the following packages:
//
// - app: Core application utilities for configuration, logging, and context management
// - gormclient: Database client factory supporting PostgreSQL and SQLite
// - redisclient: Redis client with caching support and cluster mode
// - kafkaclient: Kafka client factories for readers and writers
// - objectstorage: Multi-provider object storage interface (local, MinIO, Volcengine TOS)
// - grpcutils: gRPC middleware and interceptors for logging and request ID tracking
// - smtpmailer: SMTP email sender with TLS support
//
// # Installation
//
// To install the package, use:
//
// go get github.com/poly-workshop/go-webmods
//
// # Quick Start
//
// The typical usage pattern follows these steps:
//
// 1. Initialize the application with configuration:
//
// import "github.com/poly-workshop/go-webmods/app"
//
// func main() {
// app.Init("/path/to/workdir") // Loads configs from workdir/configs/
// // ... rest of application
// }
//
// 2. Initialize components using their factory functions:
//
// import gormclient "github.com/poly-workshop/go-webmods/gormclient"
//
// db := gormclient.NewDB(gormclient.Config{
// Driver: "postgres",
// Host: "localhost",
// Port: 5432,
// Username: "user",
// Password: "pass",
// DbName: "dbname",
// SSLMode: "disable",
// })
//
// # Configuration
//
// The app package uses Viper for layered configuration:
// - default.yaml: Default configuration
// - {MODE}.yaml: Environment-specific configuration (e.g., development.yaml, production.yaml)
// - Environment variables: Override with LOG__LEVEL, DB__HOST, etc. (using __ separator)
//
// Set the MODE environment variable to control which config file is loaded:
//
// export MODE=production
//
// # Architecture Patterns
//
// Factory Pattern: Every component uses a Config struct and factory function:
//
// component := package.NewComponent(package.Config{...})
//
// Provider Pattern: Multi-backend support (e.g., object storage):
//
// storage, err := objectstorage.NewObjectStorage(objectstorage.Config{
// ProviderType: objectstorage.ProviderLocal,
// ProviderConfig: objectstorage.ProviderConfig{
// BasePath: "/data",
// },
// })
//
// Context-Aware Logging: Structured logging with context propagation:
//
// ctx = app.WithLogAttrs(ctx, slog.String("user_id", "123"))
// slog.InfoContext(ctx, "User logged in") // Automatically includes user_id
//
// # Example Application Structure
//
// A typical application using go-webmods might look like:
//
// package main
//
// import (
// "log/slog"
// "github.com/poly-workshop/go-webmods/app"
// gormclient "github.com/poly-workshop/go-webmods/gormclient"
// redisclient "github.com/poly-workshop/go-webmods/redisclient"
// )
//
// func main() {
// // Initialize application
// app.SetCMDName("myapp")
// app.Init(".")
//
// // Initialize database
// db := gormclient.NewDB(gormclient.Config{
// Driver: "sqlite",
// DbName: "data/app.db",
// })
//
// // Initialize Redis
// rdb := redisclient.NewRDB(redisclient.Config{
// Urls: []string{"localhost:6379"},
// Password: "",
// })
//
// slog.Info("Application started successfully")
// // ... rest of application logic
// }
//
// # License
//
// This project is licensed under the MIT License.
package go_webmods