platform: Add check config func

This commit is contained in:
世界 2023-04-02 10:35:03 +08:00
parent 4db7eb9d9e
commit c3d7401ead
No known key found for this signature in database
GPG key ID: CD109927C34A63C4

View file

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