feat(osiris): reload config upon SIGHUP

Signed-off-by: Xe Iaso <me@xeiaso.net>
This commit is contained in:
Xe Iaso
2025-07-18 23:52:06 +00:00
parent 9a711f1635
commit 89b6af05a3
4 changed files with 62 additions and 21 deletions
+7 -16
View File
@@ -7,7 +7,7 @@ import (
)
var (
ErrCantBindToPort = errors.New("bind: can't bind to host:port")
ErrInvalidHostpost = errors.New("bind: invalid host:port")
)
type Bind struct {
@@ -19,25 +19,16 @@ type Bind struct {
func (b *Bind) Valid() error {
var errs []error
ln, err := net.Listen("tcp", b.HTTP)
if err != nil {
errs = append(errs, fmt.Errorf("%w %q: %w", ErrCantBindToPort, b.HTTP, err))
} else {
defer ln.Close()
if _, _, err := net.SplitHostPort(b.HTTP); err != nil {
errs = append(errs, fmt.Errorf("%w %q: %w", ErrInvalidHostpost, b.HTTP, err))
}
ln, err = net.Listen("tcp", b.HTTPS)
if err != nil {
errs = append(errs, fmt.Errorf("%w %q: %w", ErrCantBindToPort, b.HTTPS, err))
} else {
defer ln.Close()
if _, _, err := net.SplitHostPort(b.HTTPS); err != nil {
errs = append(errs, fmt.Errorf("%w %q: %w", ErrInvalidHostpost, b.HTTPS, err))
}
ln, err = net.Listen("tcp", b.Metrics)
if err != nil {
errs = append(errs, fmt.Errorf("%w %q: %w", ErrCantBindToPort, b.Metrics, err))
} else {
defer ln.Close()
if _, _, err := net.SplitHostPort(b.Metrics); err != nil {
errs = append(errs, fmt.Errorf("%w %q: %w", ErrInvalidHostpost, b.Metrics, err))
}
if len(errs) != 0 {
+5 -5
View File
@@ -24,7 +24,7 @@ func TestBindValid(t *testing.T) {
err: nil,
},
{
name: "reused ports",
name: "invalid ports",
precondition: func(t *testing.T) {
ln, err := net.Listen("tcp", ":8081")
if err != nil {
@@ -33,11 +33,11 @@ func TestBindValid(t *testing.T) {
t.Cleanup(func() { ln.Close() })
},
bind: Bind{
HTTP: ":8081",
HTTPS: ":8081",
Metrics: ":8081",
HTTP: "",
HTTPS: "",
Metrics: "",
},
err: ErrCantBindToPort,
err: ErrInvalidHostpost,
},
} {
t.Run(tt.name, func(t *testing.T) {