-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlighthouse.go
More file actions
96 lines (80 loc) · 2.09 KB
/
Copy pathlighthouse.go
File metadata and controls
96 lines (80 loc) · 2.09 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import (
"fmt"
"os"
"strconv"
"github.com/go-zoox/config"
"github.com/go-zoox/fs"
// "github.com/go-zoox/lighthouse/admin"
"github.com/go-zoox/lighthouse/constants"
"github.com/go-zoox/lighthouse/core"
"github.com/go-zoox/logger"
"github.com/urfave/cli/v2"
)
// //go:embed admin/static
// var StaticFS embed.FS
func main() {
app := &cli.App{
Name: "lighthouse",
Usage: "DNS Server",
Description: "An Easy Self Hosted DNS Server",
Version: fmt.Sprintf("%s (%s %s)", constants.Version, constants.CommitHash, constants.BuildTime),
Flags: []cli.Flag{
&cli.StringFlag{
Name: "config",
// Value: "conf/lighthouse.yaml",
Usage: "The path to the configuration file",
Aliases: []string{"c"},
},
&cli.StringFlag{
Name: "port",
Value: "53",
Usage: "The port to listen on (Only works when config file is not specified)",
Aliases: []string{"p"},
},
},
Action: func(c *cli.Context) error {
configFilePath := c.String("config")
// if configFilePath == "" {
// logger.Error("config file is required")
// os.Exit(1)
// }
if os.Getenv("MODE") == "production" {
configFilePath = "/conf/lighthouse.yaml"
}
var cfg core.Config
if configFilePath != "" {
if !fs.IsExist(configFilePath) {
logger.Error("config file(%s) not found", configFilePath)
os.Exit(1)
}
if err := config.Load(&cfg, &config.LoadOptions{
FilePath: configFilePath,
}); err != nil {
logger.Error("failed to read config file: %s", err)
os.Exit(1)
}
// j, _ := json.MarshalIndent(cfg, "", " ")
// fmt.Println(string(j))
// os.Exit(0)
} else {
port, err := strconv.Atoi(c.String("port"))
if err != nil {
logger.Error("failed to parse port: %s", err)
os.Exit(1)
}
cfg.Server.Port = int64(port)
}
// @TODO
if os.Getenv("DEBUG") == "true" {
logger.Debug("config: %v", cfg)
}
// go admin.Start(&cfg.Web, &cfg)
core.Serve(&cfg)
return nil
},
}
if err := app.Run(os.Args); err != nil {
logger.Fatal("%s", err.Error())
}
}