package services import ( "errors" "git.faercol.me/faercol/http-boot-server/bootserver/bootoption" ) var ErrUnknownClient = errors.New("unknown client") var ErrUnselectedBootOption = errors.New("unselected boot option") var ErrUnknownBootOption = errors.New("unknown boot option") type ClientHandlerService struct { clients map[string]*bootoption.Client } func NewClientHandlerService() *ClientHandlerService { return &ClientHandlerService{ clients: make(map[string]*bootoption.Client), } } func (chs *ClientHandlerService) AddClient(client *bootoption.Client) { chs.clients[client.IP] = client } func (chs *ClientHandlerService) GetClientSelectedBootOption(client string) (*bootoption.EFIApp, error) { clientDetails, ok := chs.clients[client] if !ok { return nil, ErrUnknownClient } if clientDetails.SelectedOption == "" { return nil, ErrUnselectedBootOption } for _, o := range clientDetails.Options { if o.Name == clientDetails.SelectedOption { return &o, nil } } return nil, ErrUnknownBootOption } func (chs *ClientHandlerService) SetClientBootOption(client, option string) error { clientDetails, ok := chs.clients[client] if !ok { return ErrUnknownClient } for _, o := range clientDetails.Options { if o.Name == option { clientDetails.SelectedOption = option return nil } } return ErrUnknownBootOption }