Compare commits
4 Commits
developmen
...
v0.14.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 7cc4e7831e | |||
| 5201341251 | |||
| 854819d966 | |||
| 7f6c91ae74 |
@@ -6,6 +6,8 @@
|
||||
* chore: Add new test suites for logging, OpenTelemetry initialization, gRPC server setup, and HTTP server setup.
|
||||
* chore: Enhance configuration loading tests to cover file and environment variable sources.
|
||||
* chore: Improve config test comparison robustness using JSON marshaling.
|
||||
## v0.12.3
|
||||
* chore: Upgrade to go 1.25
|
||||
|
||||
# v0.12.0
|
||||
* feat: Add support for excluding HTTP request paths from logging using configurable regular expressions.
|
||||
|
||||
4
TODO.md
4
TODO.md
@@ -1,7 +1,5 @@
|
||||
# TODO
|
||||
|
||||
- [ ] Add ability to initialize OTEL early (before app runs)
|
||||
- [ ] Spruce up the README
|
||||
- [ ] Create generic interface for implementing a service
|
||||
- [ ] Create config sample not called demo, so it is more easily reused
|
||||
- [ ] Expand config test case to cover GRPC config
|
||||
@@ -9,6 +7,8 @@
|
||||
|
||||
## Done
|
||||
|
||||
- [x] Add ability to initialize OTEL early (before app runs)
|
||||
- [x] Spruce up the README
|
||||
- [x] Test and troubleshoot GRPC Gateway support
|
||||
- [x] Finish implementing GRPC service support
|
||||
- [x] Unit tests
|
||||
|
||||
2
go.mod
2
go.mod
@@ -1,6 +1,6 @@
|
||||
module gitea.libretechconsulting.com/rmcguire/go-app
|
||||
|
||||
go 1.24.2
|
||||
go 1.25
|
||||
|
||||
require (
|
||||
buf.build/go/protovalidate v0.14.0
|
||||
|
||||
@@ -63,7 +63,7 @@ func loadConfig(configPath string) (*AppConfig, error) {
|
||||
}
|
||||
}
|
||||
|
||||
if err := env.Parse(&cfg); err != nil {
|
||||
if err := env.ParseWithOptions(&cfg, env.Options{DefaultValueTagName: "default"}); err != nil {
|
||||
return nil, fmt.Errorf("could not parse environment variables: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -59,17 +59,30 @@ func prepHTTPServer(opts *opts.AppHTTP) *http.Server {
|
||||
// Inject extra handlers if given
|
||||
// Used for grpc-gateway runtime.ServeMux handlers
|
||||
for _, h := range opts.Handlers {
|
||||
var servePath string
|
||||
|
||||
if h.Pattern != "" && h.Prefix != "" {
|
||||
l.Fatal().Str("ExactPath", h.Pattern).Str("Prefix", h.Prefix).
|
||||
Msg("Can't have both pattern and prefix match for http handler")
|
||||
}
|
||||
|
||||
if h.Prefix != "" {
|
||||
// prefix must end in / to route sub-paths
|
||||
if !strings.HasSuffix(h.Prefix, "/") {
|
||||
h.Prefix = h.Prefix + "/"
|
||||
}
|
||||
servePath = h.Prefix
|
||||
|
||||
// if enabled, the path prefix is stripped before
|
||||
// requests are sent to the handler
|
||||
if h.StripPrefix {
|
||||
h.Handler = http.StripPrefix(h.Prefix[:len(h.Prefix)-1], h.Handler)
|
||||
}
|
||||
mux.Handle(h.Prefix, otelhttp.WithRouteTag(h.Prefix, h.Handler))
|
||||
} else {
|
||||
servePath = h.Pattern
|
||||
}
|
||||
|
||||
mux.Handle(h.Prefix, otelhttp.WithRouteTag(servePath, h.Handler))
|
||||
}
|
||||
|
||||
// Add OTEL instrumentation, filter noise, set span names
|
||||
|
||||
@@ -22,7 +22,8 @@ type HTTPFunc struct {
|
||||
}
|
||||
|
||||
type HTTPHandler struct {
|
||||
Prefix string // path prefix under which to serve this handler/mux
|
||||
Prefix string // path prefix under which to serve this handler/mux, used for convenience
|
||||
Pattern string // pattern match
|
||||
StripPrefix bool // strip path before sending to handler/mux
|
||||
Handler http.Handler
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user