1
0
mirror of https://github.com/rancher/norman.git synced 2025-04-27 19:15:07 +00:00

Fix golangci-lint issues

As part of updating dapper files, golangci-lint was set to be used. This
caused a lot of lint issues to crop up, which this fixes.
This commit is contained in:
Steffan Tucker 2022-07-11 16:38:47 -06:00
parent e8b47ab4c4
commit 1e41884a06
No known key found for this signature in database
GPG Key ID: 60F043A10B1E11F6
15 changed files with 25 additions and 45 deletions

View File

@ -41,7 +41,7 @@ type HTMLResponseWriter struct {
}
func (h *HTMLResponseWriter) start(apiContext *types.APIContext, code int, obj interface{}) {
AddCommonResponseHeader(apiContext)
_ = AddCommonResponseHeader(apiContext)
apiContext.Response.Header().Set("content-type", "text/html")
apiContext.Response.Header().Set("X-Frame-Options", "SAMEORIGIN")
apiContext.Response.WriteHeader(code)
@ -68,10 +68,10 @@ func (h *HTMLResponseWriter) Write(apiContext *types.APIContext, code int, obj i
headerString = strings.Replace(headerString, "%JSURL%", jsurl, 1)
headerString = strings.Replace(headerString, "%CSSURL%", cssurl, 1)
apiContext.Response.Write([]byte(headerString))
h.Body(apiContext, apiContext.Response, obj)
_, _ = apiContext.Response.Write([]byte(headerString))
_ = h.Body(apiContext, apiContext.Response, obj)
if schemaSchema != nil {
apiContext.Response.Write(end)
_, _ = apiContext.Response.Write(end)
}
}

View File

@ -18,14 +18,14 @@ type EncodingResponseWriter struct {
}
func (j *EncodingResponseWriter) start(apiContext *types.APIContext, code int, obj interface{}) {
AddCommonResponseHeader(apiContext)
_ = AddCommonResponseHeader(apiContext)
apiContext.Response.Header().Set("content-type", j.ContentType)
apiContext.Response.WriteHeader(code)
}
func (j *EncodingResponseWriter) Write(apiContext *types.APIContext, code int, obj interface{}) {
j.start(apiContext, code, obj)
j.Body(apiContext, apiContext.Response, obj)
_ = j.Body(apiContext, apiContext.Response, obj)
}
func (j *EncodingResponseWriter) Body(apiContext *types.APIContext, writer io.Writer, obj interface{}) error {

View File

@ -39,7 +39,7 @@ func (a *APIOperations) DoDelete(url string) error {
return err
}
defer func() {
io.Copy(ioutil.Discard, resp.Body)
_, _ = io.Copy(ioutil.Discard, resp.Body)
resp.Body.Close()
}()

View File

@ -8,7 +8,7 @@ import (
"github.com/pkg/errors"
"github.com/rancher/norman/controller"
"github.com/rancher/norman/objectclient"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
err2 "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
@ -312,7 +312,6 @@ func getValue(obj interface{}, name ...string) reflect.Value {
t := v.Type()
if t.Kind() == reflect.Ptr {
v = v.Elem()
t = v.Type()
}
field := v.FieldByName(name[0])

View File

@ -99,7 +99,6 @@ func getValue(obj interface{}, name ...string) reflect.Value {
t := v.Type()
if t.Kind() == reflect.Ptr {
v = v.Elem()
t = v.Type()
}
field := v.FieldByName(name[0])

View File

@ -2,13 +2,10 @@ package controller
import (
"context"
"strings"
"time"
errors2 "github.com/pkg/errors"
"github.com/rancher/lasso/pkg/controller"
"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/cache"
@ -78,20 +75,3 @@ func isNamespace(namespace string, obj runtime.Object) bool {
}
return meta.GetNamespace() == namespace
}
func ignoreError(err error, checkString bool) bool {
err = errors2.Cause(err)
if errors.IsConflict(err) {
return true
}
if err == controller.ErrIgnore {
return true
}
if _, ok := err.(*ForgetError); ok {
return true
}
if checkString {
return strings.HasSuffix(err.Error(), "please apply your changes to the latest version and try again")
}
return false
}

View File

@ -62,5 +62,5 @@ func main() {
}
fmt.Println("Listening on 0.0.0.0:1234")
http.ListenAndServe("0.0.0.0:1234", server)
panic(http.ListenAndServe("0.0.0.0:1234", server))
}

View File

@ -517,7 +517,7 @@ func prepareDirs(dirs ...string) error {
}
func Gofmt(workDir, pkg string) error {
return filepath.Walk(filepath.Join(workDir, pkg), func(path string, info os.FileInfo, err error) error {
return filepath.Walk(filepath.Join(workDir, pkg), func(path string, info os.FileInfo, _ error) error {
if info.IsDir() {
return nil
}

View File

@ -103,7 +103,7 @@ func Parse(rw http.ResponseWriter, req *http.Request, schemas *types.Schemas, ur
result.URLBuilder, err = urlbuilder.New(req, types.APIVersion{}, result.Schemas)
result.Type = "apiRoot"
result.Schema = result.Schemas.Schema(&builtin.Version, "apiRoot")
return result, nil
return result, err
}
result.URLBuilder, err = urlbuilder.New(req, *result.Version, result.Schemas)
@ -169,9 +169,7 @@ func parseVersionAndSubContext(schemas *types.Schemas, escapedPath string) (*typ
}
version := &versions[0]
if strings.HasSuffix(escapedPath, "/") {
escapedPath = escapedPath[:len(escapedPath)-1]
}
escapedPath = strings.TrimSuffix(escapedPath, "/")
versionParts := strings.Split(version.Path, "/")
pp := strings.Split(escapedPath, "/")
@ -295,7 +293,10 @@ func parseAction(url *url.URL) (string, string) {
}
func Body(req *http.Request) (map[string]interface{}, error) {
req.ParseMultipartForm(maxFormSize)
err := req.ParseMultipartForm(maxFormSize)
if err != nil {
return nil, err
}
if req.MultipartForm != nil {
return valuesToBody(req.MultipartForm.Value), nil
}

View File

@ -10,8 +10,6 @@ import (
"k8s.io/apimachinery/pkg/util/yaml"
)
const reqMaxSize = (2 * 1 << 20) + 1
var bodyMethods = map[string]bool{
http.MethodPut: true,
http.MethodPost: true,

View File

@ -35,9 +35,9 @@ func GoroutineDumpOn(signals ...os.Signal) {
_, _ = io.WriteString(os.Stderr, p.BucketHeader(&bucket, true, len(buckets) > 1))
_, _ = io.WriteString(os.Stderr, p.StackLines(&bucket.Signature, srcLen, pkgLen, true))
}
io.Copy(os.Stderr, bytes.NewBuffer(buf))
_, _ = io.Copy(os.Stderr, bytes.NewBuffer(buf))
} else {
io.Copy(os.Stderr, src)
_, _ = io.Copy(os.Stderr, src)
}
}
}()

View File

@ -85,7 +85,7 @@ func handler(apiContext *types.APIContext) error {
}
go func() {
readerGroup.Wait()
_ = readerGroup.Wait()
close(events)
}()

View File

@ -141,7 +141,7 @@ func (s *Store) getUser(apiContext *types.APIContext) string {
func (s *Store) doAuthed(apiContext *types.APIContext, request *rest.Request) rest.Result {
start := time.Now()
defer func() {
logrus.Tracef("GET: %v, %v", time.Now().Sub(start), s.resourcePlural)
logrus.Tracef("GET: %v, %v", time.Since(start), s.resourcePlural)
}()
for _, header := range authHeaders {
@ -271,7 +271,7 @@ func (s *Store) retryList(namespace string, apiContext *types.APIContext, result
req := s.common(namespace, k8sClient.Get())
start := time.Now()
err = req.Do(apiContext.Request.Context()).Into(resultList)
logrus.Tracef("LIST: %v, %v", time.Now().Sub(start), s.resourcePlural)
logrus.Tracef("LIST: %v, %v", time.Since(start), s.resourcePlural)
if err != nil {
if i < 2 && strings.Contains(err.Error(), "Client.Timeout exceeded") {
logrus.Infof("Error on LIST %v: %v. Attempt: %v. Retrying", s.resourcePlural, err, i+1)

View File

@ -9,7 +9,7 @@ import (
)
var (
commenter = regexp.MustCompile("(?m)^( *)zzz#\\((.*)\\)\\((.*)\\)([a-z]+.*):(.*)")
commenter = regexp.MustCompile(`(?m)^( *)zzz#\\((.*)\\)\\((.*)\\)([a-z]+.*):(.*)`)
)
func JSONEncoder(writer io.Writer, v interface{}) error {

View File

@ -43,6 +43,9 @@ func (m Move) ModifySchema(s *types.Schema, schemas *types.Schemas) error {
if err != nil {
return err
}
if !ok {
return fmt.Errorf("failed to find field %s on schema %s", m.To, s.ID)
}
_, ok = toSchema.ResourceFields[toFieldName]
if ok && !strings.Contains(m.To, "/") && !m.DestDefined {
return fmt.Errorf("field %s already exists on schema %s", m.To, s.ID)