2022-07-04 08:59:27 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/sagernet/sing-box"
|
|
|
|
"github.com/sagernet/sing-box/option"
|
2022-07-06 07:01:09 +00:00
|
|
|
|
|
|
|
"github.com/goccy/go-json"
|
2022-07-04 08:59:27 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var commandCheck = &cobra.Command{
|
|
|
|
Use: "check",
|
2022-07-04 09:08:28 +00:00
|
|
|
Short: "Check configuration",
|
2022-07-04 08:59:27 +00:00
|
|
|
Run: checkConfiguration,
|
|
|
|
}
|
|
|
|
|
|
|
|
func checkConfiguration(cmd *cobra.Command, args []string) {
|
|
|
|
configContent, err := os.ReadFile(configPath)
|
|
|
|
if err != nil {
|
|
|
|
logrus.Fatal("read config: ", err)
|
|
|
|
}
|
|
|
|
var options option.Options
|
|
|
|
err = json.Unmarshal(configContent, &options)
|
|
|
|
if err != nil {
|
|
|
|
logrus.Fatal("decode config: ", err)
|
|
|
|
}
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
2022-07-07 13:47:21 +00:00
|
|
|
_, err = box.New(ctx, options)
|
2022-07-04 08:59:27 +00:00
|
|
|
if err != nil {
|
|
|
|
logrus.Fatal("create service: ", err)
|
|
|
|
}
|
|
|
|
cancel()
|
|
|
|
}
|