-
Notifications
You must be signed in to change notification settings - Fork 15
/
offline_handler.go
40 lines (32 loc) · 1003 Bytes
/
offline_handler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package flagsmith
import (
"encoding/json"
"os"
"github.com/Flagsmith/flagsmith-go-client/v4/flagengine/environments"
)
type OfflineHandler interface {
GetEnvironment() *environments.EnvironmentModel
}
type LocalFileHandler struct {
environment *environments.EnvironmentModel
}
// NewLocalFileHandler creates a new LocalFileHandler with the given path.
func NewLocalFileHandler(environmentDocumentPath string) (*LocalFileHandler, error) {
// Read the environment document from the specified path
environmentDocument, err := os.ReadFile(environmentDocumentPath)
if err != nil {
return nil, err
}
var environment environments.EnvironmentModel
if err := json.Unmarshal(environmentDocument, &environment); err != nil {
return nil, err
}
// Create and initialize the LocalFileHandler
handler := &LocalFileHandler{
environment: &environment,
}
return handler, nil
}
func (handler *LocalFileHandler) GetEnvironment() *environments.EnvironmentModel {
return handler.environment
}