From c3d7401ead1e49e6ae5ffa9da7c603c2cd24ef2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Sun, 2 Apr 2023 10:35:03 +0800 Subject: [PATCH] platform: Add check config func --- experimental/libbox/config.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/experimental/libbox/config.go b/experimental/libbox/config.go index 8a228e8c..94df3dea 100644 --- a/experimental/libbox/config.go +++ b/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 +}