Files
EdgeAPI/cmd/edge-api/main.go

49 lines
1.1 KiB
Go
Raw Normal View History

2020-07-21 17:27:00 +08:00
package main
import (
2020-10-13 20:05:13 +08:00
"encoding/json"
2020-07-22 22:17:53 +08:00
"github.com/TeaOSLab/EdgeAPI/internal/apps"
teaconst "github.com/TeaOSLab/EdgeAPI/internal/const"
2020-10-04 14:27:14 +08:00
"github.com/TeaOSLab/EdgeAPI/internal/nodes"
2020-10-13 20:05:13 +08:00
"github.com/TeaOSLab/EdgeAPI/internal/setup"
2020-09-16 09:09:21 +08:00
_ "github.com/TeaOSLab/EdgeAPI/internal/tasks"
2020-10-13 20:05:13 +08:00
"github.com/iwind/TeaGo/Tea"
2020-07-21 17:27:00 +08:00
_ "github.com/iwind/TeaGo/bootstrap"
2020-10-13 20:05:13 +08:00
"github.com/iwind/TeaGo/maps"
"log"
"os"
2020-07-21 17:27:00 +08:00
)
func main() {
2020-10-13 20:05:13 +08:00
if !Tea.IsTesting() {
Tea.Env = "prod"
}
2020-07-22 22:17:53 +08:00
app := apps.NewAppCmd()
app.Version(teaconst.Version)
app.Product(teaconst.ProductName)
2020-10-13 20:05:13 +08:00
app.Usage(teaconst.ProcessName + " [start|stop|restart|setup]")
app.On("setup", func() {
setupCmd := setup.NewSetupFromCmd()
err := setupCmd.Run()
result := maps.Map{}
if err != nil {
result["isOk"] = false
result["error"] = err.Error()
} else {
result["isOk"] = true
result["adminNodeId"] = setupCmd.AdminNodeId
result["adminNodeSecret"] = setupCmd.AdminNodeSecret
}
resultJSON, err := json.Marshal(result)
if err != nil {
log.Fatal(err.Error())
}
_, _ = os.Stdout.Write(resultJSON)
})
2020-07-22 22:17:53 +08:00
app.Run(func() {
2020-10-04 14:27:14 +08:00
nodes.NewAPINode().Start()
2020-07-22 22:17:53 +08:00
})
2020-07-21 17:27:00 +08:00
}