-
Notifications
You must be signed in to change notification settings - Fork 0
/
embedded.go
47 lines (39 loc) · 1.09 KB
/
embedded.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
package embeddedconfig
import (
"bytes"
_ "embed"
"text/template"
replicaConfig "github.com/getlantern/replica/config"
"github.com/getlantern/yaml"
globalConfig "github.com/getlantern/flashlight/v7/config/global"
)
//go:embed global.yaml.tmpl
var GlobalTemplate string
//go:generate ./download_global.sh
//go:embed global.yaml
var Global []byte
var Proxies []byte
func ExecuteAndUnmarshalGlobal(data, g any) (err error) {
var w bytes.Buffer
err = template.Must(template.New("").Parse(GlobalTemplate)).Execute(&w, data)
if err != nil {
return
}
err = yaml.Unmarshal(w.Bytes(), g)
return
}
// The replica options root extracted from the executed global config template. Replica options
// don't require any template data to derive so this can be done at init. This is used by
// getlantern/replica.
var GlobalReplicaOptions = func() (fos replicaConfig.ReplicaOptionsRoot) {
var g globalConfig.Raw
err := ExecuteAndUnmarshalGlobal(nil, &g)
if err != nil {
panic(err)
}
err = globalConfig.UnmarshalFeatureOptions(g, globalConfig.FeatureReplica, &fos)
if err != nil {
panic(err)
}
return
}()