Skip to content

Commit 21c61c9

Browse files
committed
cmd/gomobile-lib: add GetConfig func, refactor setup
1 parent 0453b91 commit 21c61c9

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

cmd/gomobile-lib/main.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"os"
1010
"strconv"
1111

12+
"github.com/libp2p/go-libp2p/p2p/host/eventbus"
13+
1214
"github.com/anywherelan/awl"
1315
"github.com/anywherelan/awl/config"
1416
"github.com/anywherelan/awl/vpn"
@@ -21,16 +23,33 @@ var (
2123

2224
// All public functions are part of the library
2325

24-
func InitServer(dataDir string, tunFD int32) (err error) {
26+
func Setup(dataDir string) {
27+
globalDataDir = dataDir
28+
_ = os.Setenv(config.AppDataDirEnvKey, dataDir)
29+
}
30+
31+
func GetConfig() string {
32+
if globalDataDir == "" {
33+
panic("call to GetConfig before Setup")
34+
}
35+
36+
conf, loadConfigErr := config.LoadConfig(eventbus.NewBus())
37+
if loadConfigErr != nil {
38+
conf = config.NewConfig(eventbus.NewBus())
39+
}
40+
41+
data := conf.Export()
42+
return string(data)
43+
}
44+
45+
func StartServer(tunFD int32) (err error) {
2546
defer func() {
2647
recovered := recover()
2748
if recovered != nil {
2849
err = fmt.Errorf("recovered panic from InitServer: %v", recovered)
2950
}
3051
}()
3152

32-
globalDataDir = dataDir
33-
_ = os.Setenv(config.AppDataDirEnvKey, dataDir)
3453
_ = os.Setenv(vpn.TunFDEnvKey, strconv.Itoa(int(tunFD)))
3554

3655
globalApp = awl.New()

0 commit comments

Comments
 (0)