1
0
Fork 0
mirror of https://github.com/diamondburned/cchat-gtk.git synced 2024-12-23 20:56:42 +00:00
cchat-gtk/internal/keyring/driver/driver.go

43 lines
860 B
Go
Raw Normal View History

package driver
import (
"fmt"
"github.com/diamondburned/cchat-gtk/internal/log"
)
type Provider interface {
Get(service string, v interface{}) error
Set(service string, v interface{}) error
}
type Store struct {
providers []Provider
}
func NewStore(providers ...Provider) Store {
return Store{providers}
}
func (s Store) Get(service string, v interface{}) error {
for _, provider := range s.providers {
if err := provider.Get(service, v); err == nil {
return nil
} else {
log.Info(err)
}
}
return fmt.Errorf("service %s not found in keyring services.", service)
}
func (s Store) Set(service string, v interface{}) error {
for _, provider := range s.providers {
if err := provider.Set(service, v); err == nil {
return nil
} else {
log.Info(err)
}
}
return fmt.Errorf("failed to set keyring for service %s", service)
}