Skip to content

Commit

Permalink
Chore: Upgrade to golang 1.19 (#585)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryantxu committed Dec 14, 2022
1 parent 2edccc9 commit 061f765
Show file tree
Hide file tree
Showing 37 changed files with 158 additions and 139 deletions.
14 changes: 7 additions & 7 deletions .drone.yml
Expand Up @@ -16,17 +16,17 @@ trigger:

steps:
- name: build
image: grafana/grafana-plugin-ci:1.3.0-alpine
image: grafana/grafana-plugin-ci:1.6.1-alpine
commands:
- mage -v build

- name: lint
image: grafana/grafana-plugin-ci:1.3.0-alpine
image: grafana/grafana-plugin-ci:1.6.1-alpine
commands:
- mage -v lint

- name: test
image: grafana/grafana-plugin-ci:1.3.0-alpine
image: grafana/grafana-plugin-ci:1.6.1-alpine
commands:
- mage -v testRace
---
Expand All @@ -44,22 +44,22 @@ trigger:

steps:
- name: build
image: grafana/grafana-plugin-ci:1.3.0-alpine
image: grafana/grafana-plugin-ci:1.6.1-alpine
commands:
- mage -v build

- name: lint
image: grafana/grafana-plugin-ci:1.3.0-alpine
image: grafana/grafana-plugin-ci:1.6.1-alpine
commands:
- mage -v lint

- name: test
image: grafana/grafana-plugin-ci:1.3.0-alpine
image: grafana/grafana-plugin-ci:1.6.1-alpine
commands:
- mage -v testRace

---
kind: signature
hmac: 54a40860ed9a1a675f7605f96b02c8dbd1b25e769cb942a27a952425a9673ad4
hmac: 329582f349b7f3a2bc25d2848d2bc3bd6232a66d1596e73b7c7317eac2a50d7e

...
4 changes: 0 additions & 4 deletions .golangci.toml
Expand Up @@ -18,15 +18,13 @@ ignore-words = ["unknwon"]
disable-all = true
enable = [
"bodyclose",
"deadcode",
"depguard",
"dogsled",
"errcheck",
"gochecknoinits",
"goconst",
"gocritic",
"goimports",
"golint",
"goprintffuncname",
"gosec",
"gosimple",
Expand All @@ -37,12 +35,10 @@ enable = [
"rowserrcheck",
"exportloopref",
"staticcheck",
"structcheck",
"stylecheck",
"typecheck",
"unconvert",
"unused",
"varcheck",
"whitespace",
"gocyclo",
"unparam",
Expand Down
2 changes: 2 additions & 0 deletions backend/data.go
Expand Up @@ -99,12 +99,14 @@ func NewQueryDataResponse() *QueryDataResponse {
// Responses is a map of RefIDs (Unique Query ID) to DataResponses.
// The QueryData method the QueryDataHandler method will set the RefId
// property on the DataResponses' frames based on these RefIDs.
//
//swagger:model
type Responses map[string]DataResponse

// DataResponse contains the results from a DataQuery.
// A map of RefIDs (unique query identifiers) to this type makes up the Responses property of a QueryDataResponse.
// The Error property is used to allow for partial success responses from the containing QueryDataResponse.
//
//swagger:model
type DataResponse struct {
// The data returned from the Query. Each Frame repeats the RefID.
Expand Down
4 changes: 2 additions & 2 deletions backend/resource/httpadapter/handler_test.go
Expand Up @@ -3,7 +3,7 @@ package httpadapter
import (
"context"
"encoding/json"
"io/ioutil"
"io"
"net/http"
"testing"

Expand Down Expand Up @@ -70,7 +70,7 @@ func TestHttpResourceHandler(t *testing.T) {
require.Equal(t, []string{"F"}, httpHandler.req.Header["X-Header-In-2"])
require.NotNil(t, httpHandler.req.Body)
defer httpHandler.req.Body.Close()
actualBodyBytes, err := ioutil.ReadAll(httpHandler.req.Body)
actualBodyBytes, err := io.ReadAll(httpHandler.req.Body)
require.NoError(t, err)
var actualJSONMap map[string]interface{}
err = json.Unmarshal(actualBodyBytes, &actualJSONMap)
Expand Down
1 change: 1 addition & 0 deletions backend/setup.go
Expand Up @@ -59,6 +59,7 @@ func SetupPluginEnvironment(pluginID string) {
r.HandleFunc("/debug/pprof/trace", pprof.Trace)

go func() {
//nolint:gosec
if err := http.ListenAndServe(portConfig, r); err != nil {
Logger.Error("Error Running profiler: %s", err.Error())
}
Expand Down
3 changes: 1 addition & 2 deletions build/common.go
Expand Up @@ -4,7 +4,6 @@ import (
"bufio"
"embed"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -340,7 +339,7 @@ func e2eProxy(mode e2e.ProxyMode) error {
// checkLinuxPtraceScope verifies that ptrace is configured as required.
func checkLinuxPtraceScope() error {
ptracePath := "/proc/sys/kernel/yama/ptrace_scope"
byteValue, err := ioutil.ReadFile(ptracePath)
byteValue, err := os.ReadFile(ptracePath)
if err != nil {
return fmt.Errorf("unable to read ptrace_scope: %w", err)
}
Expand Down
3 changes: 1 addition & 2 deletions build/utils/copy.go
Expand Up @@ -3,7 +3,6 @@ package utils
import (
"fmt"
"io"
"io/ioutil"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -105,7 +104,7 @@ func CopyRecursive(src, dst string) error {
}
}

entries, err := ioutil.ReadDir(src)
entries, err := os.ReadDir(src)
if err != nil {
return err
}
Expand Down
25 changes: 12 additions & 13 deletions build/utils/copy_test.go
@@ -1,7 +1,6 @@
package utils

import (
"io/ioutil"
"os"
"path"
"path/filepath"
Expand All @@ -12,13 +11,13 @@ import (
)

func TestCopyFile(t *testing.T) {
src, err := ioutil.TempFile("", "")
src, err := os.CreateTemp("", "")
require.NoError(t, err)
defer os.RemoveAll(src.Name())
err = ioutil.WriteFile(src.Name(), []byte("Contents"), 0600)
err = os.WriteFile(src.Name(), []byte("Contents"), 0600)
require.NoError(t, err)

dst, err := ioutil.TempFile("", "")
dst, err := os.CreateTemp("", "")
require.NoError(t, err)
defer os.RemoveAll(dst.Name())

Expand All @@ -28,7 +27,7 @@ func TestCopyFile(t *testing.T) {

// Test case where destination directory doesn't exist.
func TestCopyFile_NonExistentDestDir(t *testing.T) {
src, err := ioutil.TempFile("", "")
src, err := os.CreateTemp("", "")
require.NoError(t, err)
defer os.RemoveAll(src.Name())

Expand All @@ -37,16 +36,16 @@ func TestCopyFile_NonExistentDestDir(t *testing.T) {
}

func TestCopyRecursive_NonExistentDest(t *testing.T) {
src, err := ioutil.TempDir("", "")
src, err := os.MkdirTemp("", "")
require.NoError(t, err)
defer os.RemoveAll(src)

err = os.MkdirAll(path.Join(src, "data"), 0755)
require.NoError(t, err)
err = ioutil.WriteFile(path.Join(src, "data", "file.txt"), []byte("Test"), 0600)
err = os.WriteFile(path.Join(src, "data", "file.txt"), []byte("Test"), 0600)
require.NoError(t, err)

dstParent, err := ioutil.TempDir("", "")
dstParent, err := os.MkdirTemp("", "")
require.NoError(t, err)
defer os.RemoveAll(dstParent)

Expand All @@ -59,16 +58,16 @@ func TestCopyRecursive_NonExistentDest(t *testing.T) {
}

func TestCopyRecursive_ExistentDest(t *testing.T) {
src, err := ioutil.TempDir("", "")
src, err := os.MkdirTemp("", "")
require.NoError(t, err)
defer os.RemoveAll(src)

err = os.MkdirAll(path.Join(src, "data"), 0755)
require.NoError(t, err)
err = ioutil.WriteFile(path.Join(src, "data", "file.txt"), []byte("Test"), 0600)
err = os.WriteFile(path.Join(src, "data", "file.txt"), []byte("Test"), 0600)
require.NoError(t, err)

dst, err := ioutil.TempDir("", "")
dst, err := os.MkdirTemp("", "")
require.NoError(t, err)
defer os.RemoveAll(dst)

Expand Down Expand Up @@ -106,9 +105,9 @@ func compareDirs(t *testing.T, src, dst string) {
return nil
}

srcData, err := ioutil.ReadFile(srcPath)
srcData, err := os.ReadFile(srcPath)
require.NoError(t, err)
dstData, err := ioutil.ReadFile(dstPath)
dstData, err := os.ReadFile(dstPath)
require.NoError(t, err)

require.Equal(t, srcData, dstData)
Expand Down
3 changes: 1 addition & 2 deletions build/utils/exists_test.go
@@ -1,7 +1,6 @@
package utils

import (
"io/ioutil"
"os"
"testing"

Expand All @@ -16,7 +15,7 @@ func TestExists_NonExistent(t *testing.T) {
}

func TestExists_Existent(t *testing.T) {
f, err := ioutil.TempFile("", "")
f, err := os.CreateTemp("", "")
require.NoError(t, err)
defer os.Remove(f.Name())

Expand Down
9 changes: 4 additions & 5 deletions data/arrow_test.go
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"encoding/json"
"flag"
"io/ioutil"
"math"
"os"
"path/filepath"
Expand Down Expand Up @@ -300,12 +299,12 @@ func TestEncode(t *testing.T) {
goldenFile := filepath.Join("testdata", "all_types.golden.arrow")

if *update {
if err := ioutil.WriteFile(goldenFile, b, 0600); err != nil {
if err := os.WriteFile(goldenFile, b, 0600); err != nil {
t.Fatal(err)
}
}

want, err := ioutil.ReadFile(goldenFile)
want, err := os.ReadFile(goldenFile)
if err != nil {
t.Fatal(err)
}
Expand All @@ -332,7 +331,7 @@ func TestEncode(t *testing.T) {

func TestDecode(t *testing.T) {
goldenFile := filepath.Join("testdata", "all_types.golden.arrow")
b, err := ioutil.ReadFile(goldenFile)
b, err := os.ReadFile(goldenFile)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -391,7 +390,7 @@ func TestFromRecord(t *testing.T) {
}

// Write golden data frame to file so we can read it back in via Record reader
fd, err := ioutil.TempFile("", "data-test-from-record")
fd, err := os.CreateTemp("", "data-test-from-record")
require.NoError(t, err)
name := fd.Name()
defer os.Remove(name)
Expand Down
20 changes: 15 additions & 5 deletions data/field.go
Expand Up @@ -14,6 +14,7 @@ import (
// See NewField() for supported types.
//
// The slice data in the Field is a not exported, so methods on the Field are used to to manipulate its data.
//
//swagger:model
type Field struct {
// Name is default identifier of the field. The name does not have to be unique, but the combination
Expand All @@ -38,15 +39,24 @@ type Fields []*Field
// NewField returns a instance of *Field. Supported types for values are:
//
// Integers:
// []int8, []*int8, []int16, []*int16, []int32, []*int32, []int64, []*int64
//
// []int8, []*int8, []int16, []*int16, []int32, []*int32, []int64, []*int64
//
// Unsigned Integers:
// []uint8, []*uint8, []uint16, []*uint16, []uint32, []*uint32, []uint64, []*uint64
//
// []uint8, []*uint8, []uint16, []*uint16, []uint32, []*uint32, []uint64, []*uint64
//
// Floats:
// []float32, []*float32, []float64, []*float64
//
// []float32, []*float32, []float64, []*float64
//
// String, Bool, and Time:
// []string, []*string, []bool, []*bool, []time.Time, and []*time.Time.
//
// []string, []*string, []bool, []*bool, []time.Time, and []*time.Time.
//
// JSON:
// []json.RawMessage, []*json.RawMessage
//
// []json.RawMessage, []*json.RawMessage
//
// If an unsupported values type is passed, NewField will panic.
// nolint:gocyclo
Expand Down
1 change: 1 addition & 0 deletions data/field_type.go
Expand Up @@ -253,6 +253,7 @@ func (p FieldType) NonNullableType() FieldType {
}

// FieldTypeFromItemTypeString returns a field type from the current string
//
//nolint:goconst,gocyclo
func FieldTypeFromItemTypeString(s string) (FieldType, bool) {
switch s {
Expand Down
6 changes: 4 additions & 2 deletions data/frame.go
Expand Up @@ -30,6 +30,7 @@ import (
//
// A Frame is a general data container for Grafana. A Frame can be table data
// or time series data depending on its content and field types.
//
//swagger:model
type Frame struct {
// Name is used in some Grafana visualizations.
Expand Down Expand Up @@ -68,6 +69,7 @@ func (f *Frame) MarshalJSON() ([]byte, error) {

// Frames is a slice of Frame pointers.
// It is the main data container within a backend.DataResponse.
//
//swagger:model
type Frames []*Frame

Expand Down Expand Up @@ -491,9 +493,9 @@ func (f *Frame) StringTable(maxFields, maxRows int) (string, error) {

switch {
case f.Fields[colIdx].Type() == FieldTypeJSON:
sRow[colIdx] = fmt.Sprintf("%s", v.(json.RawMessage))
sRow[colIdx] = string(v.(json.RawMessage))
case f.Fields[colIdx].Type() == FieldTypeNullableJSON:
sRow[colIdx] = fmt.Sprintf("%s", *v.(*json.RawMessage))
sRow[colIdx] = string(*v.(*json.RawMessage))
default:
sRow[colIdx] = fmt.Sprintf("%v", val)
}
Expand Down

0 comments on commit 061f765

Please sign in to comment.