1
0
Эх сурвалжийг харах

platform: Add check config func

世界 2 жил өмнө
parent
commit
c3d7401ead

+ 17 - 0
experimental/libbox/config.go

@@ -3,6 +3,9 @@
 package libbox
 
 import (
+	"context"
+
+	"github.com/sagernet/sing-box"
 	"github.com/sagernet/sing-box/option"
 	E "github.com/sagernet/sing/common/exceptions"
 )
@@ -15,3 +18,17 @@ func parseConfig(configContent string) (option.Options, error) {
 	}
 	return options, nil
 }
+
+func CheckConfig(configContent string) error {
+	options, err := parseConfig(configContent)
+	if err != nil {
+		return err
+	}
+	ctx, cancel := context.WithCancel(context.Background())
+	defer cancel()
+	instance, err := box.New(ctx, options, nil)
+	if err == nil {
+		instance.Close()
+	}
+	return err
+}