sum7
/
yaja
Archived
1
0
Fork 0
This repository has been archived on 2020-09-27. You can view files and clone it, but cannot push or open issues or pull requests.
yaja/model/state.go

39 lines
612 B
Go

package model
import (
"encoding/json"
"errors"
"os"
"sync"
)
type State struct {
Domains map[string]*Domain
sync.Mutex
}
func ReadState(path string) (state *State, err error) {
state = &State{}
if f, err := os.Open(path); err == nil { // transform data to legacy meshviewer
if err = json.NewDecoder(f).Decode(state); err == nil {
return state, nil
} else {
return nil, err
}
} else {
return nil, err
}
}
func (s *State) UpdateDomain(d *Domain) error {
if d.FQDN == "" {
return errors.New("No fqdn exists in domain")
}
s.Lock()
s.Domains[d.FQDN] = d
s.Unlock()
return nil
}