mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-16 23:43:44 +08:00
35 lines
729 B
Go
35 lines
729 B
Go
//go:build linux || darwin
|
|
|
|
package libbox
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/sagernet/sing-box"
|
|
"github.com/sagernet/sing-box/option"
|
|
E "github.com/sagernet/sing/common/exceptions"
|
|
)
|
|
|
|
func parseConfig(configContent string) (option.Options, error) {
|
|
var options option.Options
|
|
err := options.UnmarshalJSON([]byte(configContent))
|
|
if err != nil {
|
|
return option.Options{}, E.Cause(err, "decode config")
|
|
}
|
|
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
|
|
}
|