Make golangci-lint happy, second try

This commit is contained in:
s3lph 2020-09-27 01:59:31 +02:00
parent 2b17a3c193
commit 4825c1c2af

View File

@ -149,6 +149,7 @@ func (b *Bmumble) extractFiles(msg *config.Message) []config.Message {
}
func (b *Bmumble) parseChannelPath(client *gumble.Client, name string) ([]string, error) {
// Parse the channel name as a numeric ID if passed as "ID:42"
if strings.HasPrefix(name, "ID:") {
// Parse the ID string into an int
channelID, err := strconv.ParseUint(name[3:], 10, 32)
@ -163,30 +164,30 @@ func (b *Bmumble) parseChannelPath(client *gumble.Client, name string) ([]string
return nil, errors.New("no such channel: " + name)
}
return gumbleutil.ChannelPath(c)[1:], nil
} else {
if !strings.HasPrefix(name, "/") {
return nil, errors.New("channel path must start with a '/': " + name)
}
// Special treatment for the root channel: empty slice
if name == "/" {
return make([]string, 0), nil
}
// Iterate all path components, discarding the first token, which is the empty string before the leading /
tokens := strings.Split(name, "/")
var channelPath []string
for _, token := range tokens[1:] {
// Urldecode each token and append it to the path
if channelName, err := url.PathUnescape(token); err == nil && len(channelName) > 0 {
channelPath = append(channelPath, channelName)
} else {
b.Log.WithError(err).Fatalf("Error while decoding path component '%s'", token)
return nil, err
}
}
c := client.Channels.Find(channelPath...)
if c == nil {
return nil, errors.New("no such channel: " + name)
}
return gumbleutil.ChannelPath(c)[1:], nil
}
if !strings.HasPrefix(name, "/") {
return nil, errors.New("channel path must start with a '/': " + name)
}
// Special treatment for the root channel: empty slice
if name == "/" {
return make([]string, 0), nil
}
// Iterate all path components, discarding the first token, which is the empty string before the leading /
tokens := strings.Split(name, "/")
var channelPath []string
for _, token := range tokens[1:] {
// Urldecode each token and append it to the path
if channelName, err := url.PathUnescape(token); err == nil && len(channelName) > 0 {
channelPath = append(channelPath, channelName)
} else {
b.Log.WithError(err).Fatalf("Error while decoding path component '%s'", token)
return nil, err
}
}
c := client.Channels.Find(channelPath...)
if c == nil {
return nil, errors.New("no such channel: " + name)
}
return gumbleutil.ChannelPath(c)[1:], nil
}