Skip to content

Commit 6bd8ee0

Browse files
committed
feat: Update balancer strategy handling and improve error responses in config parsing
1 parent 4edaccd commit 6bd8ee0

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

v2/config/builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ func setOutbounds(options *option.Options, input *option.Options, opt *HiddifyOp
288288
Tag: OutboundRoundRobinTag,
289289
Options: &option.BalancerOutboundOptions{
290290
Outbounds: tags,
291-
Strategy: "round-robin",
291+
Strategy: opt.BalancerStrategy,
292292
DelayAcceptableRatio: 2,
293293
// URL: opt.ConnectionTestUrl,
294294
// URLs: opt.ConnectionTestUrls,

v2/config/config_server.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ func String(s string) *string {
1919
return &s
2020
}
2121

22-
func (s *server) ParseConfig(ctx context.Context, in *ParseConfigRequest) (*ParseConfigResponse, error) {
22+
func (s *server) ParseConfig(ctx context.Context, in *ParseConfigRequest) (resp *ParseConfigResponse, err error) {
23+
defer DeferPanicToError("ParseConfig", func(recovered_err error) {
24+
resp = &ParseConfigResponse{Error: String(fmt.Sprintf("%v", recovered_err))}
25+
err = nil
26+
})
2327
ctx = libbox.BaseContext(nil)
2428
config, err := ParseConfig(ctx, &ReadOptions{Path: in.Path}, in.Debug, nil, false)
2529
if err != nil {
@@ -36,7 +40,11 @@ func (s *server) ParseConfig(ctx context.Context, in *ParseConfigRequest) (*Pars
3640
return &ParseConfigResponse{Error: String("")}, nil
3741
}
3842

39-
func (s *server) GenerateFullConfig(ctx context.Context, in *GenerateConfigRequest) (*GenerateConfigResponse, error) {
43+
func (s *server) GenerateFullConfig(ctx context.Context, in *GenerateConfigRequest) (resp *GenerateConfigResponse, err error) {
44+
defer DeferPanicToError("GenerateFullConfig", func(recovered_err error) {
45+
resp = &GenerateConfigResponse{Error: String(fmt.Sprintf("%v", recovered_err))}
46+
err = nil
47+
})
4048
ctx = libbox.BaseContext(nil)
4149
config, err := BuildConfigJson(ctx, DefaultHiddifyOptions(), &ReadOptions{Path: in.Path})
4250
if err != nil {

v2/config/hiddify_option.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type HiddifyOptions struct {
2020
Region string `json:"region,omitempty"`
2121
BlockAds bool `json:"block-ads,omitempty" overridable:"true"`
2222
UseXrayCoreWhenPossible bool `json:"use-xray-core-when-possible,omitempty" overridable:"true"`
23+
BalancerStrategy string `json:"balancer-strategy,omitempty" overridable:"true"`
2324
// GeoIPPath string `json:"geoip-path"`
2425
// GeoSitePath string `json:"geosite-path"`
2526
Rules []Rule `json:"rules,omitempty" overridable:"true"`

0 commit comments

Comments
 (0)