Don't call "bin" what is actually text

This commit is contained in:
Frank Denis 2023-06-24 22:08:01 +02:00
parent d8b1f4e7cd
commit cef4b041d7
10 changed files with 18 additions and 18 deletions

View File

@ -146,13 +146,13 @@ func ColdStart(proxy *Proxy) (*CaptivePortalHandler, error) {
if len(proxy.captivePortalMapFile) == 0 { if len(proxy.captivePortalMapFile) == 0 {
return nil, nil return nil, nil
} }
bin, err := ReadTextFile(proxy.captivePortalMapFile) lines, err := ReadTextFile(proxy.captivePortalMapFile)
if err != nil { if err != nil {
dlog.Warn(err) dlog.Warn(err)
return nil, err return nil, err
} }
ipsMap := make(CaptivePortalMap) ipsMap := make(CaptivePortalMap)
for lineNo, line := range strings.Split(string(bin), "\n") { for lineNo, line := range strings.Split(lines, "\n") {
line = TrimAndStripInlineComments(line) line = TrimAndStripInlineComments(line)
if len(line) == 0 { if len(line) == 0 {
continue continue

View File

@ -906,7 +906,7 @@ func (config *Config) loadSource(proxy *Proxy, cfgSourceName string, cfgSource *
cfgSource.Prefix, cfgSource.Prefix,
) )
if err != nil { if err != nil {
if len(source.bin) == 0 { if len(source.bin) <= 0 {
dlog.Criticalf("Unable to retrieve source [%s]: [%s]", cfgSourceName, err) dlog.Criticalf("Unable to retrieve source [%s]: [%s]", cfgSourceName, err)
return err return err
} }

View File

@ -11,7 +11,7 @@ import (
) )
func NetProbe(proxy *Proxy, address string, timeout int) error { func NetProbe(proxy *Proxy, address string, timeout int) error {
if len(address) == 0 || timeout == 0 { if len(address) <= 0 || timeout == 0 {
return nil return nil
} }
if captivePortalHandler, err := ColdStart(proxy); err == nil { if captivePortalHandler, err := ColdStart(proxy); err == nil {

View File

@ -30,13 +30,13 @@ func (plugin *PluginAllowedIP) Description() string {
func (plugin *PluginAllowedIP) Init(proxy *Proxy) error { func (plugin *PluginAllowedIP) Init(proxy *Proxy) error {
dlog.Noticef("Loading the set of allowed IP rules from [%s]", proxy.allowedIPFile) dlog.Noticef("Loading the set of allowed IP rules from [%s]", proxy.allowedIPFile)
bin, err := ReadTextFile(proxy.allowedIPFile) lines, err := ReadTextFile(proxy.allowedIPFile)
if err != nil { if err != nil {
return err return err
} }
plugin.allowedPrefixes = iradix.New() plugin.allowedPrefixes = iradix.New()
plugin.allowedIPs = make(map[string]interface{}) plugin.allowedIPs = make(map[string]interface{})
for lineNo, line := range strings.Split(bin, "\n") { for lineNo, line := range strings.Split(lines, "\n") {
line = TrimAndStripInlineComments(line) line = TrimAndStripInlineComments(line)
if len(line) == 0 { if len(line) == 0 {
continue continue

View File

@ -29,13 +29,13 @@ func (plugin *PluginAllowName) Description() string {
func (plugin *PluginAllowName) Init(proxy *Proxy) error { func (plugin *PluginAllowName) Init(proxy *Proxy) error {
dlog.Noticef("Loading the set of allowed names from [%s]", proxy.allowNameFile) dlog.Noticef("Loading the set of allowed names from [%s]", proxy.allowNameFile)
bin, err := ReadTextFile(proxy.allowNameFile) lines, err := ReadTextFile(proxy.allowNameFile)
if err != nil { if err != nil {
return err return err
} }
plugin.allWeeklyRanges = proxy.allWeeklyRanges plugin.allWeeklyRanges = proxy.allWeeklyRanges
plugin.patternMatcher = NewPatternMatcher() plugin.patternMatcher = NewPatternMatcher()
for lineNo, line := range strings.Split(string(bin), "\n") { for lineNo, line := range strings.Split(lines, "\n") {
line = TrimAndStripInlineComments(line) line = TrimAndStripInlineComments(line)
if len(line) == 0 { if len(line) == 0 {
continue continue

View File

@ -30,13 +30,13 @@ func (plugin *PluginBlockIP) Description() string {
func (plugin *PluginBlockIP) Init(proxy *Proxy) error { func (plugin *PluginBlockIP) Init(proxy *Proxy) error {
dlog.Noticef("Loading the set of IP blocking rules from [%s]", proxy.blockIPFile) dlog.Noticef("Loading the set of IP blocking rules from [%s]", proxy.blockIPFile)
bin, err := ReadTextFile(proxy.blockIPFile) lines, err := ReadTextFile(proxy.blockIPFile)
if err != nil { if err != nil {
return err return err
} }
plugin.blockedPrefixes = iradix.New() plugin.blockedPrefixes = iradix.New()
plugin.blockedIPs = make(map[string]interface{}) plugin.blockedIPs = make(map[string]interface{})
for lineNo, line := range strings.Split(string(bin), "\n") { for lineNo, line := range strings.Split(lines, "\n") {
line = TrimAndStripInlineComments(line) line = TrimAndStripInlineComments(line)
if len(line) == 0 { if len(line) == 0 {
continue continue

View File

@ -87,7 +87,7 @@ func (plugin *PluginBlockName) Description() string {
func (plugin *PluginBlockName) Init(proxy *Proxy) error { func (plugin *PluginBlockName) Init(proxy *Proxy) error {
dlog.Noticef("Loading the set of blocking rules from [%s]", proxy.blockNameFile) dlog.Noticef("Loading the set of blocking rules from [%s]", proxy.blockNameFile)
bin, err := ReadTextFile(proxy.blockNameFile) lines, err := ReadTextFile(proxy.blockNameFile)
if err != nil { if err != nil {
return err return err
} }
@ -95,7 +95,7 @@ func (plugin *PluginBlockName) Init(proxy *Proxy) error {
allWeeklyRanges: proxy.allWeeklyRanges, allWeeklyRanges: proxy.allWeeklyRanges,
patternMatcher: NewPatternMatcher(), patternMatcher: NewPatternMatcher(),
} }
for lineNo, line := range strings.Split(string(bin), "\n") { for lineNo, line := range strings.Split(lines, "\n") {
line = TrimAndStripInlineComments(line) line = TrimAndStripInlineComments(line)
if len(line) == 0 { if len(line) == 0 {
continue continue

View File

@ -39,7 +39,7 @@ func (plugin *PluginCloak) Description() string {
func (plugin *PluginCloak) Init(proxy *Proxy) error { func (plugin *PluginCloak) Init(proxy *Proxy) error {
dlog.Noticef("Loading the set of cloaking rules from [%s]", proxy.cloakFile) dlog.Noticef("Loading the set of cloaking rules from [%s]", proxy.cloakFile)
bin, err := ReadTextFile(proxy.cloakFile) lines, err := ReadTextFile(proxy.cloakFile)
if err != nil { if err != nil {
return err return err
} }
@ -47,7 +47,7 @@ func (plugin *PluginCloak) Init(proxy *Proxy) error {
plugin.createPTR = proxy.cloakedPTR plugin.createPTR = proxy.cloakedPTR
plugin.patternMatcher = NewPatternMatcher() plugin.patternMatcher = NewPatternMatcher()
cloakedNames := make(map[string]*CloakedName) cloakedNames := make(map[string]*CloakedName)
for lineNo, line := range strings.Split(bin, "\n") { for lineNo, line := range strings.Split(lines, "\n") {
line = TrimAndStripInlineComments(line) line = TrimAndStripInlineComments(line)
if len(line) == 0 { if len(line) == 0 {
continue continue

View File

@ -29,11 +29,11 @@ func (plugin *PluginForward) Description() string {
func (plugin *PluginForward) Init(proxy *Proxy) error { func (plugin *PluginForward) Init(proxy *Proxy) error {
dlog.Noticef("Loading the set of forwarding rules from [%s]", proxy.forwardFile) dlog.Noticef("Loading the set of forwarding rules from [%s]", proxy.forwardFile)
bin, err := ReadTextFile(proxy.forwardFile) lines, err := ReadTextFile(proxy.forwardFile)
if err != nil { if err != nil {
return err return err
} }
for lineNo, line := range strings.Split(string(bin), "\n") { for lineNo, line := range strings.Split(lines, "\n") {
line = TrimAndStripInlineComments(line) line = TrimAndStripInlineComments(line)
if len(line) == 0 { if len(line) == 0 {
continue continue

View File

@ -127,7 +127,7 @@ func (proxy *Proxy) addDNSListener(listenAddrStr string) {
} }
// if 'userName' is not set, continue as before // if 'userName' is not set, continue as before
if len(proxy.userName) == 0 { if len(proxy.userName) <= 0 {
if err := proxy.udpListenerFromAddr(listenUDPAddr); err != nil { if err := proxy.udpListenerFromAddr(listenUDPAddr); err != nil {
dlog.Fatal(err) dlog.Fatal(err)
} }
@ -191,7 +191,7 @@ func (proxy *Proxy) addLocalDoHListener(listenAddrStr string) {
} }
// if 'userName' is not set, continue as before // if 'userName' is not set, continue as before
if len(proxy.userName) == 0 { if len(proxy.userName) <= 0 {
if err := proxy.localDoHListenerFromAddr(listenTCPAddr); err != nil { if err := proxy.localDoHListenerFromAddr(listenTCPAddr); err != nil {
dlog.Fatal(err) dlog.Fatal(err)
} }