-
Notifications
You must be signed in to change notification settings - Fork 36
/
delta.go
53 lines (44 loc) · 1.06 KB
/
delta.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
41
42
43
44
45
46
47
48
49
50
51
52
53
package delta
import (
"embed"
"io/fs"
"os"
"sync"
"github.com/GeoNet/delta/meta"
)
//go:embed assets/*.csv
//go:embed install/*.csv
//go:embed network/*.csv
//go:embed environment/*.csv
//go:embed references/*.csv
var files embed.FS
// there can be but one
var singleton struct {
once sync.Once
set *meta.Set
err error
}
// New returns a Set pointer based on the embeded csv files.
// Multiple calls will return the same pointer and error as the first call.
func New() (*meta.Set, error) {
singleton.once.Do(func() {
singleton.set, singleton.err = NewFS(files)
})
return singleton.set, singleton.err
}
// NewFS returns a Delta pointer based on a given FS structure.
func NewFS(fs fs.FS) (*meta.Set, error) {
set, err := meta.NewSet(fs)
if err != nil {
return nil, err
}
return set, nil
}
// NewBase returns a Delta pointer based on an optional directory base prefix.
// If the base is empty then the default embeded Set will be returned.
func NewBase(base string) (*meta.Set, error) {
if base != "" {
return NewFS(os.DirFS(base))
}
return New()
}