1
0
Fork 0

chore: minor fixes

This commit is contained in:
Arthur K. 2026-01-23 11:13:44 +03:00
parent 0448f66ab2
commit 2af9e734dd
Signed by: wzray
GPG key ID: B97F30FDC4636357
6 changed files with 28 additions and 15 deletions

View file

@ -81,7 +81,7 @@ func (c Config) Validate() error {
}
}
if c.Configs.Host.set {
if c.Configs.Master.set {
if err := c.Configs.Master.Validate(); err != nil {
return fmt.Errorf("configs.master: %w", err)
}

View file

@ -30,19 +30,19 @@ func (c HostConfig) Validate() error {
}
if c.LocalAddress == "" {
return errors.New("missing local address")
return errors.New("missing local_address")
}
if c.InternalEntrypoint == "" {
return errors.New("missing internal entrypoint")
return errors.New("missing internal_entrypoint")
}
if c.ExternalEntrypoint == "" {
return errors.New("missing external entrypoint")
return errors.New("missing external_entrypoint")
}
if c.ListenAddress == "" {
return errors.New("missing listen address")
return errors.New("missing listen_address")
}
return nil

View file

@ -23,6 +23,8 @@ type Role struct {
externalDomains []string // TODO: i don't like hardcoding external/internal logic here
internalDomains []string
lock sync.RWMutex
}
func New(state *app.State, config config.HostConfig) *Role {
@ -56,6 +58,9 @@ func (r *Role) sendUpdate(domains []string, role types.Role) {
}
func (r *Role) OnTraefikUpdate(resp traefikResponse) {
r.lock.Lock()
defer r.lock.Unlock()
newInternal := resp.Domains(r.config.InternalEntrypoint)
newExternal := resp.Domains(r.config.ExternalEntrypoint)
@ -73,6 +78,9 @@ func (r *Role) OnTraefikUpdate(resp traefikResponse) {
}
func (r *Role) Dns() (types.HostState, error) {
r.lock.RLock()
defer r.lock.RUnlock()
return types.HostState{
Domains: r.internalDomains,
Address: r.config.IpAddress,
@ -81,6 +89,9 @@ func (r *Role) Dns() (types.HostState, error) {
}
func (r *Role) Nameserver() (types.HostState, error) {
r.lock.RLock()
defer r.lock.RUnlock()
return types.HostState{
Domains: r.externalDomains,
Address: r.config.IpAddress,

View file

@ -1 +0,0 @@
package host

View file

@ -39,6 +39,9 @@ func newObserver(
}
func (o *observer) pollNodes(ctx context.Context, onLeave func(types.Node) error) {
o.lock.Lock()
defer o.lock.Unlock()
nodes := o.state.Registry.Nodes()
toCheck := make([]types.Node, 0, len(nodes))
now := time.Now().UnixMilli()

View file

@ -61,7 +61,6 @@ func (c *Client) Call(host string, path string, data any, out any) error {
return fmt.Errorf("http %d: %s", httpResponse.StatusCode, string(b))
}
if out != nil {
var resp web.Response[json.RawMessage]
if err := json.NewDecoder(httpResponse.Body).Decode(&resp); err != nil {
return fmt.Errorf("decode response wrapper: %w", err)
@ -71,6 +70,7 @@ func (c *Client) Call(host string, path string, data any, out any) error {
return fmt.Errorf("error on the remote: %w", errors.New(resp.Err))
}
if out != nil {
if err := json.Unmarshal(resp.Data, out); err != nil {
return fmt.Errorf("decode response body: %w", err)
}