remove deprecated random seed and other minor staticcheck errors (#10851)

pull/10867/head
Matt Hook 2023-12-18 11:48:41 +13:00 committed by GitHub
parent 52fe09d0b1
commit 5f1f797281
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 7 deletions

View File

@ -3,11 +3,9 @@ package main
import (
"context"
"crypto/sha256"
"math/rand"
"os"
"path"
"strings"
"time"
portainer "github.com/portainer/portainer/api"
"github.com/portainer/portainer/api/apikey"
@ -631,8 +629,6 @@ func buildServer(flags *portainer.CLIFlags) portainer.Server {
}
func main() {
rand.Seed(time.Now().UnixNano())
configureLogger()
setLoggingMode("PRETTY")

View File

@ -200,7 +200,7 @@ func (handler *Handler) syncUserTeamsWithLDAPGroups(user *portainer.User, settin
func teamExists(teamName string, ldapGroups []string) bool {
for _, group := range ldapGroups {
if strings.ToLower(group) == strings.ToLower(teamName) {
if strings.EqualFold(group, teamName) {
return true
}
}

View File

@ -13,7 +13,15 @@ import (
"github.com/gorilla/mux"
)
const contextEndpoint = "endpoint"
// Note: context keys must be distinct types to prevent collisions. They are NOT key/value map's internally
// See: https://go.dev/blog/context#TOC_3.2.
// This avoids staticcheck error:
// SA1029: should not use built-in type string as key for value; define your own type to avoid collisions (staticcheck)
// https://stackoverflow.com/questions/40891345/fix-should-not-use-basic-type-string-as-key-in-context-withvalue-golint
type key int
const contextEndpoint key = 0
func WithEndpoint(endpointService dataservices.EndpointService, endpointIDParam string) mux.MiddlewareFunc {
return func(next http.Handler) http.Handler {

View File

@ -198,7 +198,6 @@ func (d *stackDeployer) remoteStack(stack *portainer.Stack, endpoint *portainer.
Str("cmd", strings.Join(cmd, " ")).
Msg("running unpacker")
rand.Seed(time.Now().UnixNano())
unpackerContainer, err := cli.ContainerCreate(ctx, &container.Config{
Image: image,
Cmd: cmd,