fix(ekko): store service name and add fallback for Server header
The name parameter passed to ekko.New() was never stored on the struct, causing the HTTP Server header to be malformed (e.g. "/vdev-snapshot+hash" instead of "warmform/vdev-snapshot+hash"). Store the name in the struct literal and add a fallback that derives the name from debug.ReadBuildInfo() if an empty string is passed.
This commit is contained in:
17
ekko/ekko.go
17
ekko/ekko.go
@@ -34,6 +34,8 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/labstack/echo-contrib/echoprometheus"
|
||||
@@ -70,6 +72,7 @@ import (
|
||||
// - WithGzipConfig(): Custom gzip compression settings
|
||||
func New(name string, options ...func(*Ekko)) (*Ekko, error) {
|
||||
ek := &Ekko{
|
||||
name: name,
|
||||
writeTimeout: 60 * time.Second,
|
||||
readHeaderTimeout: 30 * time.Second,
|
||||
}
|
||||
@@ -77,6 +80,20 @@ func New(name string, options ...func(*Ekko)) (*Ekko, error) {
|
||||
for _, o := range options {
|
||||
o(ek)
|
||||
}
|
||||
|
||||
if ek.name == "" {
|
||||
if bi, ok := debug.ReadBuildInfo(); ok && bi.Main.Path != "" {
|
||||
if idx := strings.LastIndex(bi.Main.Path, "/"); idx >= 0 {
|
||||
ek.name = bi.Main.Path[idx+1:]
|
||||
} else {
|
||||
ek.name = bi.Main.Path
|
||||
}
|
||||
}
|
||||
if ek.name == "" {
|
||||
ek.name = "ekko-app"
|
||||
}
|
||||
}
|
||||
|
||||
return ek, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user