func init() { router.RegisterRouterConfig("rules", func(data []byte) (interface{}, error) { type JsonConfig struct { RuleList []json.RawMessage `json:"rules"` DomainStrategy string `json:"domainStrategy"` } jsonConfig := new(JsonConfig) if err := json.Unmarshal(data, jsonConfig); err != nil { return nil, err } config := &RouterRuleConfig{ Rules: make([]*Rule, len(jsonConfig.RuleList)), DomainStrategy: DomainAsIs, } domainStrategy := strings.ToLower(jsonConfig.DomainStrategy) if domainStrategy == "alwaysip" { config.DomainStrategy = AlwaysUseIP } else if domainStrategy == "ipifnonmatch" { config.DomainStrategy = UseIPIfNonMatch } for idx, rawRule := range jsonConfig.RuleList { rule := ParseRule(rawRule) config.Rules[idx] = rule } return config, nil }) }
func init() { router.RegisterRouterConfig("rules", func(data []byte) (interface{}, error) { type JsonConfig struct { RuleList []json.RawMessage `json:"rules"` } jsonConfig := new(JsonConfig) if err := json.Unmarshal(data, jsonConfig); err != nil { return nil, err } config := NewRouterRuleConfig() for _, rawRule := range jsonConfig.RuleList { rule := ParseRule(rawRule) config.Add(rule) } return config, nil }) }
func init() { router.RegisterRouterConfig("rules", func(data []byte) (interface{}, error) { type JsonConfig struct { RuleList []json.RawMessage `json:"rules"` ResolveDomain bool `json:"resolveDomain"` } jsonConfig := new(JsonConfig) if err := json.Unmarshal(data, jsonConfig); err != nil { return nil, err } config := &RouterRuleConfig{ Rules: make([]*Rule, len(jsonConfig.RuleList)), ResolveDomain: jsonConfig.ResolveDomain, } for idx, rawRule := range jsonConfig.RuleList { rule := ParseRule(rawRule) config.Rules[idx] = rule } return config, nil }) }