github.com/Asutorufa/yuhaiin@v0.3.6-0.20240502055049-7984da7023a0/pkg/protos/config/bypass/bypass.go (about) 1 package bypass 2 3 import ( 4 "bytes" 5 "strings" 6 ) 7 8 type ModeEnum interface { 9 Mode() Mode 10 Unknown() bool 11 GetTag() string 12 GetResolveStrategy() ResolveStrategy 13 } 14 15 func (m Mode) Mode() Mode { return m } 16 func (m Mode) Unknown() bool { 17 _, ok := Mode_name[int32(m)] 18 return !ok 19 } 20 21 func (Mode) GetTag() string { return "" } 22 func (Mode) GetResolveStrategy() ResolveStrategy { return ResolveStrategy_default } 23 24 func (f *ModeConfig) StoreKV(fs [][]byte) { 25 for _, x := range fs { 26 i := bytes.IndexByte(x, '=') 27 if i == -1 { 28 continue 29 } 30 31 key := strings.ToLower(string(x[:i])) 32 33 if key == "tag" { 34 f.Tag = strings.ToLower(string(x[i+1:])) 35 } 36 37 if key == "resolve_strategy" { 38 f.ResolveStrategy = ResolveStrategy(ResolveStrategy_value[strings.ToLower(string(x[i+1:]))]) 39 } 40 } 41 } 42 43 func (f *ModeConfig) ToModeEnum() ModeEnum { 44 if f.ResolveStrategy == ResolveStrategy_default && f.Tag == "" { 45 return f.Mode 46 } 47 48 return &modeConfig{f.Mode, f.Tag, f.ResolveStrategy} 49 } 50 51 type modeConfig struct { 52 mode Mode 53 Tag string 54 ResolveStrategy ResolveStrategy 55 } 56 57 func (m modeConfig) Mode() Mode { return m.mode } 58 func (m modeConfig) GetTag() string { return m.Tag } 59 func (modeConfig) Unknown() bool { return false } 60 func (m modeConfig) GetResolveStrategy() ResolveStrategy { return m.ResolveStrategy }