Skip to content

Commit 90cc8ea

Browse files
authored
** BREAKING CHANGES ** - NEW LOGGER (#3)
- BREAKING CHANGES - All packages with the logging dependencies have been refactored to implement the standard log/slog. - Removed logging package and replaced with the new logutil and logsrv packages. - Close functions errors are now joined with the parent ones and not silently logged anymore. - Remove deprecated functions. - Updated Web-service example. - Updated license. - Updated dependencies.
1 parent 9dba27c commit 90cc8ea

File tree

102 files changed

+2593
-2221
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+2593
-2221
lines changed

LICENSE

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
MIT LICENSE
22

33
Copyright (c) 2025-2025 Nicola Asuni - Tecnick.com LTD :
4-
- changes after merging gogen back into https://github.com/tecnickcom/gogen
4+
- All changes from 2025-11-01 after merging
5+
gosrvlib back into https://github.com/tecnickcom/gogen
56
Copyright (c) 2020-2025 Vonage :
67
- gogen refactored and extended into https://github.com/Vonage/gosrvlib
78
Copyright (c) 2014-2020 Nicola Asuni - Tecnick.com LTD :
8-
- original gogen project https://github.com/tecnickcom/gogen
9+
- Original gogen project https://github.com/tecnickcom/gogen
910

1011
Permission is hereby granted, free of charge, to any person obtaining a copy
1112
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 70 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -40,74 +40,76 @@ The package documentation is available at: [https://pkg.go.dev/github.com/tecnic
4040
**gogen** offers a comprehensive collection of well-tested Go packages.
4141
Each package adheres to common conventions and coding standards, making them easy to integrate into your projects.
4242

43-
* [awsopt](pkg/awsopt) – Utilities for configuring common AWS options with the aws-sdk-go-v2 library.
44-
* [awssecretcache](pkg/awssecretcache) – Client for retrieving and caching secrets from AWS Secrets Manager.
45-
* [bootstrap](pkg/bootstrap) – Helpers for application bootstrap and initialization.
46-
* [config](pkg/config) – Utilities for configuration loading and management.
47-
* [countrycode](pkg/countrycode) – Functions for country code lookup and validation.
48-
* [countryphone](pkg/countryphone) – Phone number parsing and country association.
49-
* [decint](pkg/decint) – Helpers for parsing and formatting decimal integers.
50-
* [devlake](pkg/devlake) – Client for the DevLake Webhook API.
51-
* [dnscache](pkg/dnscache) – DNS resolution with caching support.
52-
* [encode](pkg/encode) – Utilities for data encoding and serialization.
53-
* [encrypt](pkg/encrypt) – Helpers for encryption and decryption.
54-
* [enumbitmap](pkg/enumbitmap) – Encode and decode slices of enumeration strings as integer bitmap values.
55-
* [enumcache](pkg/enumcache) – Caching for enumeration values with bitmap support.
56-
* [enumdb](pkg/enumdb) – Helpers for storing and retrieving enumeration sets in databases.
57-
* [errutil](pkg/errutil) – Error utility functions, including error tracing.
58-
* [filter](pkg/filter) – Generic rule-based filtering for struct slices.
59-
* [healthcheck](pkg/healthcheck) – Health check endpoints and logic.
60-
* [httpclient](pkg/httpclient) – HTTP client with enhanced features.
61-
* [httpretrier](pkg/httpretrier) – HTTP request retry logic.
62-
* [httpreverseproxy](pkg/httpreverseproxy) – HTTP reverse proxy implementation.
63-
* [httpserver](pkg/httpserver) – HTTP server setup and management.
64-
* [httputil](pkg/httputil) – HTTP utility functions.
65-
* [jsendx](pkg/httputil/jsendx) – Helpers for JSend-compliant responses.
66-
* [ipify](pkg/ipify) – IP address lookup using the ipify service.
67-
* [jirasrv](pkg/jirasrv) – Client for Jira server APIs.
68-
* [jwt](pkg/jwt) – JSON Web Token creation and validation.
69-
* [kafka](pkg/kafka) – Kafka producer and consumer utilities.
70-
* [kafkacgo](pkg/kafkacgo) – Kafka integration using CGO bindings.
71-
* [logging](pkg/logging) – Structured logging utilities.
72-
* [maputil](pkg/maputil) – Helpers for Go map manipulation.
73-
* [metrics](pkg/metrics) – Metrics collection and reporting.
74-
* [prometheus](pkg/metrics/prometheus) – Prometheus metrics exporter.
75-
* [statsd](pkg/metrics/statsd) – StatsD metrics exporter.
76-
* [mysqllock](pkg/mysqllock) – Distributed locking using MySQL.
77-
* [numtrie](pkg/numtrie) – Trie data structure for numeric keys with partial matching.
78-
* [paging](pkg/paging) – Helpers for data pagination.
79-
* [passwordhash](pkg/passwordhash) – Password hashing and verification.
80-
* [passwordpwned](pkg/passwordpwned) – Password breach checking via HaveIBeenPwned.
81-
* [periodic](pkg/periodic) – Periodic task scheduling.
82-
* [phonekeypad](pkg/phonekeypad) – Phone keypad mapping utilities.
83-
* [profiling](pkg/profiling) – Application profiling tools.
84-
* [randkey](pkg/randkey) – Helpers for random key generation.
85-
* [random](pkg/random) – Utilities for random data generation.
86-
* [redact](pkg/redact) – Data redaction helpers.
87-
* [redis](pkg/redis) – Redis client and utilities.
88-
* [retrier](pkg/retrier) – Retry logic for operations.
89-
* [s3](pkg/s3) – Helpers for AWS S3 integration.
90-
* [sfcache](pkg/sfcache) – Simple, in-memory, thread-safe, fixed-size, single-flight cache for expensive lookups.
91-
* [slack](pkg/slack) – Client for sending messages via the Slack API Webhook.
92-
* [sleuth](pkg/sleuth) – Client for the Sleuth.io API.
93-
* [sliceutil](pkg/sliceutil) – Utilities for slice manipulation.
94-
* [sqlconn](pkg/sqlconn) – Helpers for SQL database connections.
95-
* [sqltransaction](pkg/sqltransaction) – SQL transaction management.
96-
* [sqlutil](pkg/sqlutil) – SQL utility functions.
97-
* [sqlxtransaction](pkg/sqlxtransaction) – Helpers for SQLX transactions.
98-
* [sqs](pkg/sqs) – Utilities for AWS SQS (Simple Queue Service) integration.
99-
* [stringkey](pkg/stringkey) – Create unique hash keys from multiple strings.
100-
* [stringmetric](pkg/stringmetric) – String similarity and distance metrics.
101-
* [testutil](pkg/testutil) – Utilities for testing.
102-
* [threadsafe](pkg/threadsafe) – Thread-safe data structures.
103-
* [tsmap](pkg/threadsafe/tsmap) – Thread-safe map implementation.
104-
* [tsslice](pkg/threadsafe/tsslice) – Thread-safe slice implementation.
105-
* [timeutil](pkg/timeutil) – Time and date utilities.
106-
* [traceid](pkg/traceid) – Trace ID generation and management.
107-
* [typeutil](pkg/typeutil) – Type conversion and utility functions.
108-
* [uidc](pkg/uidc) – Unique identifier generation.
109-
* [validator](pkg/validator) – Data validation utilities.
110-
* [valkey](pkg/valkey) – Wrapper client for interacting with valkey.io, an open-source in-memory data store.
43+
* [awsopt](pkg/awsopt) - Utilities for configuring common AWS options with the aws-sdk-go-v2 library.
44+
* [awssecretcache](pkg/awssecretcache) - Client for retrieving and caching secrets from AWS Secrets Manager.
45+
* [bootstrap](pkg/bootstrap) - Helpers for application bootstrap and initialization.
46+
* [config](pkg/config) - Utilities for configuration loading and management.
47+
* [countrycode](pkg/countrycode) - Functions for country code lookup and validation.
48+
* [countryphone](pkg/countryphone) - Phone number parsing and country association.
49+
* [decint](pkg/decint) - Helpers for parsing and formatting decimal integers.
50+
* [devlake](pkg/devlake) - Client for the DevLake Webhook API.
51+
* [dnscache](pkg/dnscache) - DNS resolution with caching support.
52+
* [encode](pkg/encode) - Utilities for data encoding and serialization.
53+
* [encrypt](pkg/encrypt) - Helpers for encryption and decryption.
54+
* [enumbitmap](pkg/enumbitmap) - Encode and decode slices of enumeration strings as integer bitmap values.
55+
* [enumcache](pkg/enumcache) - Caching for enumeration values with bitmap support.
56+
* [enumdb](pkg/enumdb) - Helpers for storing and retrieving enumeration sets in databases.
57+
* [errutil](pkg/errutil) - Error utility functions, including error tracing.
58+
* [filter](pkg/filter) - Generic rule-based filtering for struct slices.
59+
* [healthcheck](pkg/healthcheck) - Health check endpoints and logic.
60+
* [httpclient](pkg/httpclient) - HTTP client with enhanced features.
61+
* [httpretrier](pkg/httpretrier) - HTTP request retry logic.
62+
* [httpreverseproxy](pkg/httpreverseproxy) - HTTP reverse proxy implementation.
63+
* [httpserver](pkg/httpserver) - HTTP server setup and management.
64+
* [httputil](pkg/httputil) - HTTP utility functions.
65+
* [jsendx](pkg/httputil/jsendx) - Helpers for JSend-compliant responses.
66+
* [ipify](pkg/ipify) - IP address lookup using the ipify service.
67+
* [jirasrv](pkg/jirasrv) - Client for Jira server APIs.
68+
* [jwt](pkg/jwt) - JSON Web Token creation and validation.
69+
* [kafka](pkg/kafka) - Kafka producer and consumer utilities.
70+
* [kafkacgo](pkg/kafkacgo) - Kafka integration using CGO bindings.
71+
* [logsrv](pkg/logsrv) - Default slog logger with zerolog handler.
72+
* [logutil](pkg/logutil) - Logging utilities for log/slog integration.
73+
* [logutil](pkg/logutil) - General log utilities for log/slog integration.
74+
* [maputil](pkg/maputil) - Helpers for Go map manipulation.
75+
* [metrics](pkg/metrics) - Metrics collection and reporting.
76+
* [prometheus](pkg/metrics/prometheus) - Prometheus metrics exporter.
77+
* [statsd](pkg/metrics/statsd) - StatsD metrics exporter.
78+
* [mysqllock](pkg/mysqllock) - Distributed locking using MySQL.
79+
* [numtrie](pkg/numtrie) - Trie data structure for numeric keys with partial matching.
80+
* [paging](pkg/paging) - Helpers for data pagination.
81+
* [passwordhash](pkg/passwordhash) - Password hashing and verification.
82+
* [passwordpwned](pkg/passwordpwned) - Password breach checking via HaveIBeenPwned.
83+
* [periodic](pkg/periodic) - Periodic task scheduling.
84+
* [phonekeypad](pkg/phonekeypad) - Phone keypad mapping utilities.
85+
* [profiling](pkg/profiling) - Application profiling tools.
86+
* [randkey](pkg/randkey) - Helpers for random key generation.
87+
* [random](pkg/random) - Utilities for random data generation.
88+
* [redact](pkg/redact) - Data redaction helpers.
89+
* [redis](pkg/redis) - Redis client and utilities.
90+
* [retrier](pkg/retrier) - Retry logic for operations.
91+
* [s3](pkg/s3) - Helpers for AWS S3 integration.
92+
* [sfcache](pkg/sfcache) - Simple, in-memory, thread-safe, fixed-size, single-flight cache for expensive lookups.
93+
* [slack](pkg/slack) - Client for sending messages via the Slack API Webhook.
94+
* [sleuth](pkg/sleuth) - Client for the Sleuth.io API.
95+
* [sliceutil](pkg/sliceutil) - Utilities for slice manipulation.
96+
* [sqlconn](pkg/sqlconn) - Helpers for SQL database connections.
97+
* [sqltransaction](pkg/sqltransaction) - SQL transaction management.
98+
* [sqlutil](pkg/sqlutil) - SQL utility functions.
99+
* [sqlxtransaction](pkg/sqlxtransaction) - Helpers for SQLX transactions.
100+
* [sqs](pkg/sqs) - Utilities for AWS SQS (Simple Queue Service) integration.
101+
* [stringkey](pkg/stringkey) - Create unique hash keys from multiple strings.
102+
* [stringmetric](pkg/stringmetric) - String similarity and distance metrics.
103+
* [testutil](pkg/testutil) - Utilities for testing.
104+
* [threadsafe](pkg/threadsafe) - Thread-safe data structures.
105+
* [tsmap](pkg/threadsafe/tsmap) - Thread-safe map implementation.
106+
* [tsslice](pkg/threadsafe/tsslice) - Thread-safe slice implementation.
107+
* [timeutil](pkg/timeutil) - Time and date utilities.
108+
* [traceid](pkg/traceid) - Trace ID generation and management.
109+
* [typeutil](pkg/typeutil) - Type conversion and utility functions.
110+
* [uidc](pkg/uidc) - Unique identifier generation.
111+
* [validator](pkg/validator) - Data validation utilities.
112+
* [valkey](pkg/valkey) - Wrapper client for interacting with valkey.io, an open-source in-memory data store.
111113

112114
-----------------------------------------------------------------
113115

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.109.3
1+
1.111.1

examples/service/cmd/main.go

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
package main
33

44
import (
5+
"log/slog"
6+
"os"
7+
58
"github.com/gogenexampleowner/gogenexample/internal/cli"
69
"github.com/tecnickcom/gogen/pkg/bootstrap"
7-
"github.com/tecnickcom/gogen/pkg/logging"
8-
"go.uber.org/zap"
10+
"github.com/tecnickcom/gogen/pkg/logsrv"
11+
"github.com/tecnickcom/gogen/pkg/logutil"
912
)
1013

1114
var (
@@ -16,18 +19,33 @@ var (
1619
programRelease = "0" //nolint:gochecknoglobals
1720
)
1821

22+
// exitFn define tha exit function and can be overwritten for testing.
23+
var exitFn = os.Exit //nolint:gochecknoglobals
24+
1925
func main() {
20-
_, _ = logging.NewDefaultLogger(cli.AppName, programVersion, programRelease, "json", "debug")
26+
logattr := []logutil.Attr{
27+
slog.String("program", cli.AppName),
28+
slog.String("version", programVersion),
29+
slog.String("release", programRelease),
30+
}
31+
logcfg, _ := logutil.NewConfig(
32+
logutil.WithOutWriter(os.Stderr),
33+
logutil.WithFormat(logutil.FormatJSON),
34+
logutil.WithLevel(logutil.LevelDebug),
35+
logutil.WithCommonAttr(logattr...),
36+
)
37+
l := logsrv.NewLogger(logcfg)
2138

2239
rootCmd, err := cli.New(programVersion, programRelease, bootstrap.Bootstrap)
2340
if err != nil {
24-
logging.LogFatal("UNABLE TO START THE PROGRAM", zap.Error(err))
25-
return
41+
l.With(slog.Any("error", err)).Error("UNABLE TO START THE PROGRAM")
42+
exitFn(1)
2643
}
2744

2845
// execute the root command and log errors (if any)
2946
err = rootCmd.Execute()
3047
if err != nil {
31-
logging.LogFatal("UNABLE TO RUN THE COMMAND", zap.Error(err))
48+
l.With(slog.Any("error", err)).Error("UNABLE TO RUN THE COMMAND")
49+
exitFn(2)
3250
}
3351
}

examples/service/cmd/main_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ import (
77

88
"github.com/gogenexampleowner/gogenexample/internal/cli"
99
"github.com/stretchr/testify/require"
10-
"github.com/tecnickcom/gogen/pkg/logging"
1110
"github.com/tecnickcom/gogen/pkg/testutil"
12-
"go.uber.org/zap"
1311
)
1412

1513
//nolint:paralleltest
@@ -31,23 +29,25 @@ func TestProgramVersion(t *testing.T) {
3129

3230
//nolint:paralleltest
3331
func TestMainCliError(t *testing.T) {
34-
oldLogFatal := logging.LogFatal
32+
oldExitFn := exitFn
3533

36-
defer func() { logging.LogFatal = oldLogFatal }()
34+
defer func() { exitFn = oldExitFn }()
35+
36+
exitFn = func(v int) { panic(v) }
3737

38-
logging.LogFatal = zap.L().Panic
3938
os.Args = []string{cli.AppName, "--INVALID"}
4039

4140
require.Panics(t, main, "Expected to fail because of invalid argument name")
4241
}
4342

4443
//nolint:paralleltest
4544
func TestMainCliExecuteError(t *testing.T) {
46-
oldLogFatal := logging.LogFatal
45+
oldExitFn := exitFn
46+
47+
defer func() { exitFn = oldExitFn }()
4748

48-
defer func() { logging.LogFatal = oldLogFatal }()
49+
exitFn = func(v int) { panic(v) }
4950

50-
logging.LogFatal = zap.L().Panic
5151
os.Args = []string{cli.AppName, "--logLevel=INVALID"}
5252

5353
require.Panics(t, main, "Expected to fail because of invalid argument value")

examples/service/go.mod

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ require (
1111
github.com/spf13/cobra v1.10.1
1212
github.com/spf13/viper v1.21.0
1313
github.com/stretchr/testify v1.11.1
14-
github.com/tecnickcom/gogen v1.109.3
15-
go.uber.org/zap v1.27.0
14+
github.com/tecnickcom/gogen v1.111.1
1615
)
1716

1817
require (
@@ -76,8 +75,12 @@ require (
7675
github.com/prometheus/client_model v0.6.2 // indirect
7776
github.com/prometheus/common v0.67.2 // indirect
7877
github.com/prometheus/procfs v0.19.2 // indirect
78+
github.com/rs/zerolog v1.34.0 // indirect
7979
github.com/sagikazarmark/crypt v0.31.0 // indirect
8080
github.com/sagikazarmark/locafero v0.12.0 // indirect
81+
github.com/samber/lo v1.52.0 // indirect
82+
github.com/samber/slog-common v0.19.0 // indirect
83+
github.com/samber/slog-zerolog/v2 v2.9.0 // indirect
8184
github.com/spf13/afero v1.15.0 // indirect
8285
github.com/spf13/cast v1.10.0 // indirect
8386
github.com/spf13/pflag v1.0.10 // indirect
@@ -95,6 +98,7 @@ require (
9598
go.opentelemetry.io/otel/trace v1.38.0 // indirect
9699
go.uber.org/mock v0.6.0 // indirect
97100
go.uber.org/multierr v1.11.0 // indirect
101+
go.uber.org/zap v1.27.0 // indirect
98102
go.yaml.in/yaml/v2 v2.4.3 // indirect
99103
go.yaml.in/yaml/v3 v3.0.4 // indirect
100104
golang.org/x/crypto v0.43.0 // indirect
@@ -108,9 +112,9 @@ require (
108112
golang.org/x/time v0.14.0 // indirect
109113
golang.org/x/tools v0.38.0 // indirect
110114
google.golang.org/api v0.255.0 // indirect
111-
google.golang.org/genproto v0.0.0-20251103181224-f26f9409b101 // indirect
112-
google.golang.org/genproto/googleapis/api v0.0.0-20251103181224-f26f9409b101 // indirect
113-
google.golang.org/genproto/googleapis/rpc v0.0.0-20251103181224-f26f9409b101 // indirect
115+
google.golang.org/genproto v0.0.0-20251110190251-83f479183930 // indirect
116+
google.golang.org/genproto/googleapis/api v0.0.0-20251110190251-83f479183930 // indirect
117+
google.golang.org/genproto/googleapis/rpc v0.0.0-20251110190251-83f479183930 // indirect
114118
google.golang.org/grpc v1.76.0 // indirect
115119
google.golang.org/protobuf v1.36.10 // indirect
116120
gopkg.in/yaml.v3 v3.0.1 // indirect

0 commit comments

Comments
 (0)