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 +}