Lint: Resolve linter issues

occurred with new Go / golangci-lint version

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2024-02-18 13:42:00 +01:00
parent e0e9f6d80a
commit 673ed1e29a
Signed by: luzifer
SSH key fingerprint: SHA256:/xtE5lCgiRDQr8SLxHMS92ZBlACmATUmF1crK16Ks4E
16 changed files with 31 additions and 31 deletions

View file

@ -11,7 +11,7 @@ func init() {
cli.Add(cliRegistryEntry{ cli.Add(cliRegistryEntry{
Name: "actor-docs", Name: "actor-docs",
Description: "Generate markdown documentation for available actors", Description: "Generate markdown documentation for available actors",
Run: func(args []string) error { Run: func([]string) error {
doc, err := generateActorDocs() doc, err := generateActorDocs()
if err != nil { if err != nil {
return errors.Wrap(err, "generating actor docs") return errors.Wrap(err, "generating actor docs")

View file

@ -9,7 +9,7 @@ func init() {
cli.Add(cliRegistryEntry{ cli.Add(cliRegistryEntry{
Name: "reset-secrets", Name: "reset-secrets",
Description: "Remove encrypted data to reset encryption passphrase", Description: "Remove encrypted data to reset encryption passphrase",
Run: func(args []string) error { Run: func([]string) error {
if err := accessService.RemoveAllExtendedTwitchCredentials(); err != nil { if err := accessService.RemoveAllExtendedTwitchCredentials(); err != nil {
return errors.Wrap(err, "resetting Twitch credentials") return errors.Wrap(err, "resetting Twitch credentials")
} }

View file

@ -11,7 +11,7 @@ func init() {
cli.Add(cliRegistryEntry{ cli.Add(cliRegistryEntry{
Name: "tpl-docs", Name: "tpl-docs",
Description: "Generate markdown documentation for available template functions", Description: "Generate markdown documentation for available template functions",
Run: func(args []string) error { Run: func([]string) error {
doc, err := generateTplDocs() doc, err := generateTplDocs()
if err != nil { if err != nil {
return errors.Wrap(err, "generating template docs") return errors.Wrap(err, "generating template docs")

View file

@ -6,7 +6,7 @@ func init() {
cli.Add(cliRegistryEntry{ cli.Add(cliRegistryEntry{
Name: "validate-config", Name: "validate-config",
Description: "Try to load configuration file and report errors if any", Description: "Try to load configuration file and report errors if any",
Run: func(args []string) error { Run: func([]string) error {
return errors.Wrap( return errors.Wrap(
loadConfig(cfg.Config), loadConfig(cfg.Config),
"loading config", "loading config",

View file

@ -46,7 +46,7 @@ func init() {
} }
func registerEditorFrontend() { func registerEditorFrontend() {
router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { router.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) {
f, err := configEditorFrontend.Open("editor/index.html") f, err := configEditorFrontend.Open("editor/index.html")
if err != nil { if err != nil {
http.Error(w, errors.Wrap(err, "opening index.html").Error(), http.StatusNotFound) http.Error(w, errors.Wrap(err, "opening index.html").Error(), http.StatusNotFound)
@ -56,7 +56,7 @@ func registerEditorFrontend() {
io.Copy(w, f) //nolint:errcheck,gosec io.Copy(w, f) //nolint:errcheck,gosec
}) })
router.HandleFunc("/editor/vars.json", func(w http.ResponseWriter, r *http.Request) { router.HandleFunc("/editor/vars.json", func(w http.ResponseWriter, _ *http.Request) {
if err := json.NewEncoder(w).Encode(struct { if err := json.NewEncoder(w).Encode(struct {
DefaultBotScopes []string DefaultBotScopes []string
IRCBadges []string IRCBadges []string

View file

@ -11,7 +11,7 @@ import (
) )
func init() { func init() {
tplFuncs.Register("arg", func(m *irc.Message, r *plugins.Rule, fields *plugins.FieldCollection) interface{} { tplFuncs.Register("arg", func(m *irc.Message, _ *plugins.Rule, _ *plugins.FieldCollection) interface{} {
return func(arg int) (string, error) { return func(arg int) (string, error) {
msgParts := strings.Split(m.Trailing(), " ") msgParts := strings.Split(m.Trailing(), " ")
if len(msgParts) <= arg { if len(msgParts) <= arg {
@ -30,7 +30,7 @@ func init() {
}, },
}) })
tplFuncs.Register("chatterHasBadge", func(m *irc.Message, r *plugins.Rule, fields *plugins.FieldCollection) interface{} { tplFuncs.Register("chatterHasBadge", func(m *irc.Message, _ *plugins.Rule, _ *plugins.FieldCollection) interface{} {
return func(badge string) bool { return func(badge string) bool {
badges := twitch.ParseBadgeLevels(m) badges := twitch.ParseBadgeLevels(m)
return badges.Has(badge) return badges.Has(badge)
@ -57,7 +57,7 @@ func init() {
}, },
) )
tplFuncs.Register("group", func(m *irc.Message, r *plugins.Rule, fields *plugins.FieldCollection) interface{} { tplFuncs.Register("group", func(m *irc.Message, r *plugins.Rule, _ *plugins.FieldCollection) interface{} {
return func(idx int, fallback ...string) (string, error) { return func(idx int, fallback ...string) (string, error) {
fields := r.GetMatchMessage().FindStringSubmatch(m.Trailing()) fields := r.GetMatchMessage().FindStringSubmatch(m.Trailing())
if len(fields) <= idx { if len(fields) <= idx {
@ -94,7 +94,7 @@ func init() {
}, },
) )
tplFuncs.Register("tag", func(m *irc.Message, r *plugins.Rule, fields *plugins.FieldCollection) interface{} { tplFuncs.Register("tag", func(m *irc.Message, _ *plugins.Rule, _ *plugins.FieldCollection) interface{} {
return func(tag string) string { return m.Tags[tag] } return func(tag string) string { return m.Tags[tag] }
}, plugins.TemplateFuncDocumentation{ }, plugins.TemplateFuncDocumentation{
Description: "Takes the message sent to the channel, returns the value of the tag specified", Description: "Takes the message sent to the channel, returns the value of the tag specified",

View file

@ -135,7 +135,7 @@ func Register(args plugins.RegistrationArguments) (err error) {
return fmt.Errorf("registering API route: %w", err) return fmt.Errorf("registering API route: %w", err)
} }
args.RegisterTemplateFunction("channelCounter", func(m *irc.Message, r *plugins.Rule, fields *plugins.FieldCollection) interface{} { args.RegisterTemplateFunction("channelCounter", func(_ *irc.Message, _ *plugins.Rule, fields *plugins.FieldCollection) interface{} {
return func(name string) (string, error) { return func(name string) (string, error) {
channel, err := fields.String("channel") channel, err := fields.String("channel")
if err != nil { if err != nil {

View file

@ -37,7 +37,7 @@ func actionDelete(channel, _, msgid, _ string) (err error) {
} }
func getActionTimeout(duration time.Duration) actionFn { func getActionTimeout(duration time.Duration) actionFn {
return func(channel, match, msgid, user string) error { return func(channel, match, _, user string) error {
return errors.Wrap( return errors.Wrap(
botTwitchClient.BanUser( botTwitchClient.BanUser(
context.Background(), context.Background(),

View file

@ -93,7 +93,7 @@ func Register(args plugins.RegistrationArguments) (err error) {
return fmt.Errorf("registering API: %w", err) return fmt.Errorf("registering API: %w", err)
} }
args.RegisterTemplateFunction("lastQuoteIndex", func(m *irc.Message, r *plugins.Rule, fields *plugins.FieldCollection) interface{} { args.RegisterTemplateFunction("lastQuoteIndex", func(m *irc.Message, _ *plugins.Rule, _ *plugins.FieldCollection) interface{} {
return func() (int, error) { return func() (int, error) {
return getMaxQuoteIdx(db, plugins.DeriveChannel(m, nil)) return getMaxQuoteIdx(db, plugins.DeriveChannel(m, nil))
} }

View file

@ -20,7 +20,7 @@ const moduleName = "raffle"
var apiRoutes = []plugins.HTTPRouteRegistrationArgs{ var apiRoutes = []plugins.HTTPRouteRegistrationArgs{
{ {
Description: "Lists all raffles known to the bot", Description: "Lists all raffles known to the bot",
HandlerFunc: handleWrap(func(w http.ResponseWriter, r *http.Request, _ map[string]uint64) (any, error) { HandlerFunc: handleWrap(func(_ http.ResponseWriter, _ *http.Request, _ map[string]uint64) (any, error) {
ras, err := dbc.List() ras, err := dbc.List()
return ras, errors.Wrap(err, "fetching raffles from database") return ras, errors.Wrap(err, "fetching raffles from database")
}, nil), }, nil),
@ -34,7 +34,7 @@ var apiRoutes = []plugins.HTTPRouteRegistrationArgs{
{ {
Description: "Creates a new raffle based on the data in the body", Description: "Creates a new raffle based on the data in the body",
HandlerFunc: handleWrap(func(w http.ResponseWriter, r *http.Request, _ map[string]uint64) (any, error) { HandlerFunc: handleWrap(func(_ http.ResponseWriter, r *http.Request, _ map[string]uint64) (any, error) {
var ra raffle var ra raffle
if err := json.NewDecoder(r.Body).Decode(&ra); err != nil { if err := json.NewDecoder(r.Body).Decode(&ra); err != nil {
return nil, errors.Wrap(err, "parsing raffle from body") return nil, errors.Wrap(err, "parsing raffle from body")
@ -52,7 +52,7 @@ var apiRoutes = []plugins.HTTPRouteRegistrationArgs{
{ {
Description: "Deletes raffle by given ID including all entries", Description: "Deletes raffle by given ID including all entries",
HandlerFunc: handleWrap(func(w http.ResponseWriter, r *http.Request, ids map[string]uint64) (any, error) { HandlerFunc: handleWrap(func(_ http.ResponseWriter, _ *http.Request, ids map[string]uint64) (any, error) {
return nil, errors.Wrap(dbc.Delete(ids["id"]), "fetching raffle from database") return nil, errors.Wrap(dbc.Delete(ids["id"]), "fetching raffle from database")
}, []string{"id"}), }, []string{"id"}),
Method: http.MethodDelete, Method: http.MethodDelete,
@ -71,7 +71,7 @@ var apiRoutes = []plugins.HTTPRouteRegistrationArgs{
{ {
Description: "Gets raffle by given ID including all entries", Description: "Gets raffle by given ID including all entries",
HandlerFunc: handleWrap(func(w http.ResponseWriter, r *http.Request, ids map[string]uint64) (any, error) { HandlerFunc: handleWrap(func(_ http.ResponseWriter, _ *http.Request, ids map[string]uint64) (any, error) {
ra, err := dbc.Get(ids["id"]) ra, err := dbc.Get(ids["id"])
return ra, errors.Wrap(err, "fetching raffle from database") return ra, errors.Wrap(err, "fetching raffle from database")
}, []string{"id"}), }, []string{"id"}),
@ -91,7 +91,7 @@ var apiRoutes = []plugins.HTTPRouteRegistrationArgs{
{ {
Description: "Updates the given raffle (needs to include the whole object, not just changed fields)", Description: "Updates the given raffle (needs to include the whole object, not just changed fields)",
HandlerFunc: handleWrap(func(w http.ResponseWriter, r *http.Request, ids map[string]uint64) (any, error) { HandlerFunc: handleWrap(func(_ http.ResponseWriter, r *http.Request, ids map[string]uint64) (any, error) {
var ra raffle var ra raffle
if err := json.NewDecoder(r.Body).Decode(&ra); err != nil { if err := json.NewDecoder(r.Body).Decode(&ra); err != nil {
return nil, errors.Wrap(err, "parsing raffle from body") return nil, errors.Wrap(err, "parsing raffle from body")
@ -119,7 +119,7 @@ var apiRoutes = []plugins.HTTPRouteRegistrationArgs{
{ {
Description: "Resets the raffle (remove entries, reset status & start/close time) given by its ID", Description: "Resets the raffle (remove entries, reset status & start/close time) given by its ID",
HandlerFunc: handleWrap(func(w http.ResponseWriter, r *http.Request, ids map[string]uint64) (any, error) { HandlerFunc: handleWrap(func(_ http.ResponseWriter, _ *http.Request, ids map[string]uint64) (any, error) {
return nil, errors.Wrap(dbc.Reset(ids["id"]), "resetting raffle") return nil, errors.Wrap(dbc.Reset(ids["id"]), "resetting raffle")
}, []string{"id"}), }, []string{"id"}),
Method: http.MethodPut, Method: http.MethodPut,
@ -138,7 +138,7 @@ var apiRoutes = []plugins.HTTPRouteRegistrationArgs{
{ {
Description: "Duplicates the raffle given by its ID", Description: "Duplicates the raffle given by its ID",
HandlerFunc: handleWrap(func(w http.ResponseWriter, r *http.Request, ids map[string]uint64) (any, error) { HandlerFunc: handleWrap(func(_ http.ResponseWriter, _ *http.Request, ids map[string]uint64) (any, error) {
return nil, errors.Wrap(dbc.Clone(ids["id"]), "cloning raffle") return nil, errors.Wrap(dbc.Clone(ids["id"]), "cloning raffle")
}, []string{"id"}), }, []string{"id"}),
Method: http.MethodPut, Method: http.MethodPut,
@ -157,7 +157,7 @@ var apiRoutes = []plugins.HTTPRouteRegistrationArgs{
{ {
Description: "Closes the raffle given by its ID", Description: "Closes the raffle given by its ID",
HandlerFunc: handleWrap(func(w http.ResponseWriter, r *http.Request, ids map[string]uint64) (any, error) { HandlerFunc: handleWrap(func(_ http.ResponseWriter, _ *http.Request, ids map[string]uint64) (any, error) {
return nil, errors.Wrap(dbc.Close(ids["id"]), "closing raffle") return nil, errors.Wrap(dbc.Close(ids["id"]), "closing raffle")
}, []string{"id"}), }, []string{"id"}),
Method: http.MethodPut, Method: http.MethodPut,
@ -176,7 +176,7 @@ var apiRoutes = []plugins.HTTPRouteRegistrationArgs{
{ {
Description: "Picks a winner for the given raffle (this does NOT close the raffle, use only on closed raffle!)", Description: "Picks a winner for the given raffle (this does NOT close the raffle, use only on closed raffle!)",
HandlerFunc: handleWrap(func(w http.ResponseWriter, r *http.Request, ids map[string]uint64) (any, error) { HandlerFunc: handleWrap(func(_ http.ResponseWriter, _ *http.Request, ids map[string]uint64) (any, error) {
return nil, errors.Wrap(dbc.PickWinner(ids["id"]), "picking winner") return nil, errors.Wrap(dbc.PickWinner(ids["id"]), "picking winner")
}, []string{"id"}), }, []string{"id"}),
Method: http.MethodPut, Method: http.MethodPut,
@ -195,7 +195,7 @@ var apiRoutes = []plugins.HTTPRouteRegistrationArgs{
{ {
Description: "Re-opens a raffle for additional entries, only Status and CloseAt are modified", Description: "Re-opens a raffle for additional entries, only Status and CloseAt are modified",
HandlerFunc: handleWrap(func(w http.ResponseWriter, r *http.Request, ids map[string]uint64) (any, error) { HandlerFunc: handleWrap(func(_ http.ResponseWriter, r *http.Request, ids map[string]uint64) (any, error) {
dur, err := strconv.ParseInt(r.URL.Query().Get("duration"), 10, 64) dur, err := strconv.ParseInt(r.URL.Query().Get("duration"), 10, 64)
if err != nil { if err != nil {
return nil, errors.Wrap(err, "parsing duration") return nil, errors.Wrap(err, "parsing duration")
@ -227,7 +227,7 @@ var apiRoutes = []plugins.HTTPRouteRegistrationArgs{
{ {
Description: "Starts a raffle making it available for entries", Description: "Starts a raffle making it available for entries",
HandlerFunc: handleWrap(func(w http.ResponseWriter, r *http.Request, ids map[string]uint64) (any, error) { HandlerFunc: handleWrap(func(_ http.ResponseWriter, _ *http.Request, ids map[string]uint64) (any, error) {
return nil, errors.Wrap(dbc.Start(ids["id"]), "starting raffle") return nil, errors.Wrap(dbc.Start(ids["id"]), "starting raffle")
}, []string{"id"}), }, []string{"id"}),
Method: http.MethodPut, Method: http.MethodPut,
@ -246,7 +246,7 @@ var apiRoutes = []plugins.HTTPRouteRegistrationArgs{
{ {
Description: "Dismisses a previously picked winner and picks a new one", Description: "Dismisses a previously picked winner and picks a new one",
HandlerFunc: handleWrap(func(w http.ResponseWriter, r *http.Request, ids map[string]uint64) (any, error) { HandlerFunc: handleWrap(func(_ http.ResponseWriter, _ *http.Request, ids map[string]uint64) (any, error) {
return nil, errors.Wrap(dbc.RedrawWinner(ids["id"], ids["winner"]), "re-picking winner") return nil, errors.Wrap(dbc.RedrawWinner(ids["id"], ids["winner"]), "re-picking winner")
}, []string{"id", "winner"}), }, []string{"id", "winner"}),
Method: http.MethodPut, Method: http.MethodPut,

View file

@ -99,7 +99,7 @@ func (r resolver) resolveFinal(link string, cookieJar *cookiejar.Jar, callStack
} }
client := &http.Client{ client := &http.Client{
CheckRedirect: func(req *http.Request, via []*http.Request) error { CheckRedirect: func(*http.Request, []*http.Request) error {
return http.ErrUseLastResponse return http.ErrUseLastResponse
}, },
Jar: cookieJar, Jar: cookieJar,

View file

@ -182,7 +182,7 @@ func main() {
router.Use(corsMiddleware) router.Use(corsMiddleware)
router.HandleFunc("/openapi.html", handleSwaggerHTML) router.HandleFunc("/openapi.html", handleSwaggerHTML)
router.HandleFunc("/openapi.json", handleSwaggerRequest) router.HandleFunc("/openapi.json", handleSwaggerRequest)
router.HandleFunc("/selfcheck", func(w http.ResponseWriter, r *http.Request) { router.HandleFunc("/selfcheck", func(w http.ResponseWriter, _ *http.Request) {
http.Error(w, runID, http.StatusOK) http.Error(w, runID, http.StatusOK)
}) })

View file

@ -23,7 +23,7 @@ func CopyObjects(src, target *gorm.DB, objects ...any) (err error) {
return errors.Wrap(err, "cleaning target table") return errors.Wrap(err, "cleaning target table")
} }
if err = src.FindInBatches(copySlice, copyBatchSize, func(tx *gorm.DB, _ int) error { if err = src.FindInBatches(copySlice, copyBatchSize, func(*gorm.DB, int) error {
if err = target.Save(copySlice).Error; err != nil { if err = target.Save(copySlice).Error; err != nil {
if errors.Is(err, gorm.ErrEmptySlice) { if errors.Is(err, gorm.ErrEmptySlice) {
// That's fine and no reason to exit here // That's fine and no reason to exit here

View file

@ -24,7 +24,7 @@ type (
StartedAt time.Time `json:"started_at"` StartedAt time.Time `json:"started_at"`
Language string `json:"language"` Language string `json:"language"`
ThumbnailURL string `json:"thumbnail_url"` ThumbnailURL string `json:"thumbnail_url"`
TagIds []string `json:"tag_ids"` TagIds []string `json:"tag_ids"` //revive:disable-line:var-naming // Disabled to prevent breaking change
IsMature bool `json:"is_mature"` IsMature bool `json:"is_mature"`
} }
) )

View file

@ -34,7 +34,7 @@ func loadPlugins(pluginDir string) error {
args := getRegistrationArguments() args := getRegistrationArguments()
return errors.Wrap(filepath.Walk(pluginDir, func(currentPath string, info os.FileInfo, err error) error { return errors.Wrap(filepath.Walk(pluginDir, func(currentPath string, _ os.FileInfo, err error) error {
if err != nil { if err != nil {
return err return err
} }

View file

@ -141,7 +141,7 @@ func TestAllowExecuteDisableOnTemplate(t *testing.T) {
} { } {
// We don't test the message formatter here but only the disable functionality // We don't test the message formatter here but only the disable functionality
// so we fake the result of the evaluation // so we fake the result of the evaluation
r.msgFormatter = func(tplString string, m *irc.Message, r *Rule, fields *FieldCollection) (string, error) { r.msgFormatter = func(string, *irc.Message, *Rule, *FieldCollection) (string, error) {
return msg, nil return msg, nil
} }