mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 03:32:33 +08:00
chore: better converter
Some checks are pending
Trigger CMFA Update / trigger-CMFA-update (push) Waiting to run
Some checks are pending
Trigger CMFA Update / trigger-CMFA-update (push) Waiting to run
This commit is contained in:
parent
4f8a5a5f54
commit
1db3e4583b
|
@ -942,7 +942,12 @@ rule-providers:
|
||||||
interval: 259200
|
interval: 259200
|
||||||
path: /path/to/save/file.yaml
|
path: /path/to/save/file.yaml
|
||||||
type: file
|
type: file
|
||||||
rule3: # mrs类型ruleset,目前仅支持domain和ipcidr,可以通过“mihomo convert-ruleset domain yaml XXX.yaml XXX.mrs”转换得到
|
rule3:
|
||||||
|
# mrs类型ruleset,目前仅支持domain和ipcidr(即不支持classical),
|
||||||
|
# behavior=domain,format=yaml 可以通过“mihomo convert-ruleset domain yaml XXX.yaml XXX.mrs”转换得到
|
||||||
|
# behavior=domain,format=text 可以通过“mihomo convert-ruleset domain text XXX.text XXX.mrs”转换得到
|
||||||
|
# behavior=ipcidr,format=yaml 可以通过“mihomo convert-ruleset ipcidr yaml XXX.yaml XXX.mrs”转换得到
|
||||||
|
# behavior=ipcidr,format=text 可以通过“mihomo convert-ruleset ipcidr text XXX.text XXX.mrs”转换得到
|
||||||
type: http
|
type: http
|
||||||
url: "url"
|
url: "url"
|
||||||
format: mrs
|
format: mrs
|
||||||
|
|
|
@ -3,6 +3,7 @@ package provider
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/metacubex/mihomo/component/trie"
|
"github.com/metacubex/mihomo/component/trie"
|
||||||
C "github.com/metacubex/mihomo/constant"
|
C "github.com/metacubex/mihomo/constant"
|
||||||
|
@ -43,6 +44,10 @@ func (d *domainStrategy) Reset() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *domainStrategy) Insert(rule string) {
|
func (d *domainStrategy) Insert(rule string) {
|
||||||
|
if strings.ContainsRune(rule, '/') {
|
||||||
|
log.Warnln("invalid domain:[%s]", rule)
|
||||||
|
return
|
||||||
|
}
|
||||||
err := d.domainTrie.Insert(rule, struct{}{})
|
err := d.domainTrie.Insert(rule, struct{}{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnln("invalid domain:[%s]", rule)
|
log.Warnln("invalid domain:[%s]", rule)
|
||||||
|
|
|
@ -2,6 +2,7 @@ package provider
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
@ -16,6 +17,9 @@ func ConvertToMrs(buf []byte, behavior P.RuleBehavior, format P.RuleFormat, w io
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if strategy.Count() == 0 {
|
||||||
|
return errors.New("empty rule")
|
||||||
|
}
|
||||||
if _strategy, ok := strategy.(mrsRuleStrategy); ok {
|
if _strategy, ok := strategy.(mrsRuleStrategy); ok {
|
||||||
var encoder *zstd.Encoder
|
var encoder *zstd.Encoder
|
||||||
encoder, err = zstd.NewWriter(w)
|
encoder, err = zstd.NewWriter(w)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user