From 4825c1c2afc34bcb04a80e3ced351b2242426b21 Mon Sep 17 00:00:00 2001 From: s3lph <5564491+s3lph@users.noreply.github.com> Date: Sun, 27 Sep 2020 01:59:31 +0200 Subject: [PATCH] Make golangci-lint happy, second try --- bridge/mumble/helpers.go | 51 ++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/bridge/mumble/helpers.go b/bridge/mumble/helpers.go index 1ba14536..11008df9 100644 --- a/bridge/mumble/helpers.go +++ b/bridge/mumble/helpers.go @@ -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 }