Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Client struct {
mu sync.RWMutex
context Context
switchers map[string]*Switcher
snapshot *Snapshot

authMu sync.Mutex
authToken string
Expand Down Expand Up @@ -79,6 +80,45 @@ func (c *Client) Context() Context {
return c.context
}

func LoadSnapshot(options *LoadSnapshotOptions) (int, error) {
return defaultClient().LoadSnapshot(options)
}

func (c *Client) LoadSnapshot(options *LoadSnapshotOptions) (int, error) {
snapshot, err := loadSnapshotFromFile(c.Context())
if err != nil {
return 0, err
}

c.mu.Lock()
c.snapshot = snapshot
c.mu.Unlock()

return c.SnapshotVersion(), nil
}

func SnapshotVersion() int {
return defaultClient().SnapshotVersion()
}

func (c *Client) SnapshotVersion() int {
c.mu.RLock()
defer c.mu.RUnlock()

if c.snapshot == nil {
return 0
}

return c.snapshot.Domain.Version
}

func (c *Client) snapshotState() *Snapshot {
c.mu.RLock()
defer c.mu.RUnlock()

return c.snapshot
}

func defaultClient() *Client {
if client := globalClient.Load(); client != nil {
return client
Expand Down
12 changes: 12 additions & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,22 @@ type RemoteCriteriaError struct {
RemoteError
}

type LocalCriteriaError struct {
message string
}

func (e *LocalCriteriaError) Error() string {
return e.message
}

func newRemoteAuthError(format string, args ...any) error {
return &RemoteAuthError{RemoteError: RemoteError{message: fmt.Sprintf(format, args...)}}
}

func newRemoteCriteriaError(format string, args ...any) error {
return &RemoteCriteriaError{RemoteError: RemoteError{message: fmt.Sprintf(format, args...)}}
}

func newLocalCriteriaError(format string, args ...any) error {
return &LocalCriteriaError{message: fmt.Sprintf(format, args...)}
}
Loading
Loading