chore: minor fixes
This commit is contained in:
parent
0448f66ab2
commit
2af9e734dd
6 changed files with 28 additions and 15 deletions
|
|
@ -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 {
|
if err := c.Configs.Master.Validate(); err != nil {
|
||||||
return fmt.Errorf("configs.master: %w", err)
|
return fmt.Errorf("configs.master: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,19 +30,19 @@ func (c HostConfig) Validate() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.LocalAddress == "" {
|
if c.LocalAddress == "" {
|
||||||
return errors.New("missing local address")
|
return errors.New("missing local_address")
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.InternalEntrypoint == "" {
|
if c.InternalEntrypoint == "" {
|
||||||
return errors.New("missing internal entrypoint")
|
return errors.New("missing internal_entrypoint")
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.ExternalEntrypoint == "" {
|
if c.ExternalEntrypoint == "" {
|
||||||
return errors.New("missing external entrypoint")
|
return errors.New("missing external_entrypoint")
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.ListenAddress == "" {
|
if c.ListenAddress == "" {
|
||||||
return errors.New("missing listen address")
|
return errors.New("missing listen_address")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,8 @@ type Role struct {
|
||||||
|
|
||||||
externalDomains []string // TODO: i don't like hardcoding external/internal logic here
|
externalDomains []string // TODO: i don't like hardcoding external/internal logic here
|
||||||
internalDomains []string
|
internalDomains []string
|
||||||
|
|
||||||
|
lock sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(state *app.State, config config.HostConfig) *Role {
|
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) {
|
func (r *Role) OnTraefikUpdate(resp traefikResponse) {
|
||||||
|
r.lock.Lock()
|
||||||
|
defer r.lock.Unlock()
|
||||||
|
|
||||||
newInternal := resp.Domains(r.config.InternalEntrypoint)
|
newInternal := resp.Domains(r.config.InternalEntrypoint)
|
||||||
newExternal := resp.Domains(r.config.ExternalEntrypoint)
|
newExternal := resp.Domains(r.config.ExternalEntrypoint)
|
||||||
|
|
||||||
|
|
@ -73,6 +78,9 @@ func (r *Role) OnTraefikUpdate(resp traefikResponse) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Role) Dns() (types.HostState, error) {
|
func (r *Role) Dns() (types.HostState, error) {
|
||||||
|
r.lock.RLock()
|
||||||
|
defer r.lock.RUnlock()
|
||||||
|
|
||||||
return types.HostState{
|
return types.HostState{
|
||||||
Domains: r.internalDomains,
|
Domains: r.internalDomains,
|
||||||
Address: r.config.IpAddress,
|
Address: r.config.IpAddress,
|
||||||
|
|
@ -81,6 +89,9 @@ func (r *Role) Dns() (types.HostState, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Role) Nameserver() (types.HostState, error) {
|
func (r *Role) Nameserver() (types.HostState, error) {
|
||||||
|
r.lock.RLock()
|
||||||
|
defer r.lock.RUnlock()
|
||||||
|
|
||||||
return types.HostState{
|
return types.HostState{
|
||||||
Domains: r.externalDomains,
|
Domains: r.externalDomains,
|
||||||
Address: r.config.IpAddress,
|
Address: r.config.IpAddress,
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
package host
|
|
||||||
|
|
@ -39,6 +39,9 @@ func newObserver(
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *observer) pollNodes(ctx context.Context, onLeave func(types.Node) error) {
|
func (o *observer) pollNodes(ctx context.Context, onLeave func(types.Node) error) {
|
||||||
|
o.lock.Lock()
|
||||||
|
defer o.lock.Unlock()
|
||||||
|
|
||||||
nodes := o.state.Registry.Nodes()
|
nodes := o.state.Registry.Nodes()
|
||||||
toCheck := make([]types.Node, 0, len(nodes))
|
toCheck := make([]types.Node, 0, len(nodes))
|
||||||
now := time.Now().UnixMilli()
|
now := time.Now().UnixMilli()
|
||||||
|
|
|
||||||
|
|
@ -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))
|
return fmt.Errorf("http %d: %s", httpResponse.StatusCode, string(b))
|
||||||
}
|
}
|
||||||
|
|
||||||
if out != nil {
|
|
||||||
var resp web.Response[json.RawMessage]
|
var resp web.Response[json.RawMessage]
|
||||||
if err := json.NewDecoder(httpResponse.Body).Decode(&resp); err != nil {
|
if err := json.NewDecoder(httpResponse.Body).Decode(&resp); err != nil {
|
||||||
return fmt.Errorf("decode response wrapper: %w", err)
|
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))
|
return fmt.Errorf("error on the remote: %w", errors.New(resp.Err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if out != nil {
|
||||||
if err := json.Unmarshal(resp.Data, out); err != nil {
|
if err := json.Unmarshal(resp.Data, out); err != nil {
|
||||||
return fmt.Errorf("decode response body: %w", err)
|
return fmt.Errorf("decode response body: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue