Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: format code with Go fmt #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build ignore
// +build ignore

package main
Expand Down
11 changes: 7 additions & 4 deletions pkg/api/docs/definitions/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@
//
// SecurityDefinitions:
// basic:
// type: basic
//
// type: basic
//
// api_key:
// type: apiKey
// name: Authorization
// in: header
//
// type: apiKey
// name: Authorization
// in: header
//
// swagger:meta
package definitions
44 changes: 23 additions & 21 deletions pkg/components/imguploader/azureblobuploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,15 @@ func tryget(headers map[string][]string, key string) string {

/*
Based on Azure docs:
Link: http://msdn.microsoft.com/en-us/library/windowsazure/dd179428.aspx#Constructing_Element

1) Retrieve all headers for the resource that begin with x-ms-, including the x-ms-date header.
2) Convert each HTTP header name to lowercase.
3) Sort the headers lexicographically by header name, in ascending order. Note that each header may appear only once in the string.
4) Unfold the string by replacing any breaking white space with a single space.
5) Trim any white space around the colon in the header.
6) Finally, append a new line character to each canonicalized header in the resulting list. Construct the CanonicalizedHeaders string by concatenating all headers in this list into a single string.

Link: http://msdn.microsoft.com/en-us/library/windowsazure/dd179428.aspx#Constructing_Element

1) Retrieve all headers for the resource that begin with x-ms-, including the x-ms-date header.
2) Convert each HTTP header name to lowercase.
3) Sort the headers lexicographically by header name, in ascending order. Note that each header may appear only once in the string.
4) Unfold the string by replacing any breaking white space with a single space.
5) Trim any white space around the colon in the header.
6) Finally, append a new line character to each canonicalized header in the resulting list. Construct the CanonicalizedHeaders string by concatenating all headers in this list into a single string.
*/
func (a *Auth) canonicalizedHeaders(req *http.Request) string {
var buffer bytes.Buffer
Expand All @@ -288,25 +289,26 @@ func (a *Auth) canonicalizedHeaders(req *http.Request) string {

/*
Based on Azure docs
Link: http://msdn.microsoft.com/en-us/library/windowsazure/dd179428.aspx#Constructing_Element

1) Beginning with an empty string (""), append a forward slash (/), followed by the name of the account that owns the resource being accessed.
2) Append the resource's encoded URI path, without any query parameters.
3) Retrieve all query parameters on the resource URI, including the comp parameter if it exists.
4) Convert all parameter names to lowercase.
5) Sort the query parameters lexicographically by parameter name, in ascending order.
6) URL-decode each query parameter name and value.
7) Append each query parameter name and value to the string in the following format, making sure to include the colon (:) between the name and the value:
parameter-name:parameter-value
Link: http://msdn.microsoft.com/en-us/library/windowsazure/dd179428.aspx#Constructing_Element

1. Beginning with an empty string (""), append a forward slash (/), followed by the name of the account that owns the resource being accessed.
2. Append the resource's encoded URI path, without any query parameters.
3. Retrieve all query parameters on the resource URI, including the comp parameter if it exists.
4. Convert all parameter names to lowercase.
5. Sort the query parameters lexicographically by parameter name, in ascending order.
6. URL-decode each query parameter name and value.
7. Append each query parameter name and value to the string in the following format, making sure to include the colon (:) between the name and the value:
parameter-name:parameter-value

8) If a query parameter has more than one value, sort all values lexicographically, then include them in a comma-separated list:
parameter-name:parameter-value-1,parameter-value-2,parameter-value-n
8. If a query parameter has more than one value, sort all values lexicographically, then include them in a comma-separated list:
parameter-name:parameter-value-1,parameter-value-2,parameter-value-n

9) Append a new line character (\n) after each name-value pair.

Rules:
1) Avoid using the new line character (\n) in values for query parameters. If it must be used, ensure that it does not affect the format of the canonicalized resource string.
2) Avoid using commas in query parameter values.
1. Avoid using the new line character (\n) in values for query parameters. If it must be used, ensure that it does not affect the format of the canonicalized resource string.
2. Avoid using commas in query parameter values.
*/
func (a *Auth) canonicalizedResource(req *http.Request) string {
var buffer bytes.Buffer
Expand Down
4 changes: 2 additions & 2 deletions pkg/components/loki/logproto/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (m *Entry) MarshalToSizedBuffer(dAtA []byte) (int, error) {
return len(dAtA) - i, nil
}

//nolint: gocyclo
// nolint: gocyclo
func (m *Stream) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
Expand Down Expand Up @@ -248,7 +248,7 @@ func (m *Stream) Unmarshal(dAtA []byte) error {
return nil
}

//nolint: gocyclo
// nolint: gocyclo
func (m *Entry) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
Expand Down
61 changes: 37 additions & 24 deletions pkg/components/simplejson/simplejson.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ func (j *Json) Del(key string) {
// for `key` in its `map` representation
//
// useful for chaining operations (to traverse a nested JSON):
// js.Get("top_level").Get("dict").Get("value").Int()
//
// js.Get("top_level").Get("dict").Get("value").Int()
func (j *Json) Get(key string) *Json {
m, err := j.Map()
if err == nil {
Expand All @@ -168,7 +169,7 @@ func (j *Json) Get(key string) *Json {
// GetPath searches for the item as specified by the branch
// without the need to deep dive using Get()'s.
//
// js.GetPath("top_level", "dict")
// js.GetPath("top_level", "dict")
func (j *Json) GetPath(branch ...string) *Json {
jin := j
for _, p := range branch {
Expand All @@ -182,7 +183,8 @@ func (j *Json) GetPath(branch ...string) *Json {
//
// this is the analog to Get when accessing elements of
// a json array instead of a json object:
// js.Get("top_level").Get("array").GetIndex(1).Get("key").Int()
//
// js.Get("top_level").Get("array").GetIndex(1).Get("key").Int()
func (j *Json) GetIndex(index int) *Json {
a, err := j.Array()
if err == nil {
Expand All @@ -198,9 +200,10 @@ func (j *Json) GetIndex(index int) *Json {
// indicating success or failure
//
// useful for chained operations when success is important:
// if data, ok := js.Get("top_level").CheckGetIndex(0); ok {
// log.Println(data)
// }
//
// if data, ok := js.Get("top_level").CheckGetIndex(0); ok {
// log.Println(data)
// }
func (j *Json) CheckGetIndex(index int) (*Json, bool) {
a, err := j.Array()
if err == nil {
Expand All @@ -226,9 +229,10 @@ func (j *Json) SetIndex(index int, val interface{}) {
// a `bool` identifying success or failure
//
// useful for chained operations when success is important:
// if data, ok := js.Get("top_level").CheckGet("inner"); ok {
// log.Println(data)
// }
//
// if data, ok := js.Get("top_level").CheckGet("inner"); ok {
// log.Println(data)
// }
func (j *Json) CheckGet(key string) (*Json, bool) {
m, err := j.Map()
if err == nil {
Expand Down Expand Up @@ -303,9 +307,10 @@ func (j *Json) StringArray() ([]string, error) {
// MustArray guarantees the return of a `[]interface{}` (with optional default)
//
// useful when you want to iterate over array values in a succinct manner:
// for i, v := range js.Get("results").MustArray() {
// fmt.Println(i, v)
// }
//
// for i, v := range js.Get("results").MustArray() {
// fmt.Println(i, v)
// }
func (j *Json) MustArray(args ...[]interface{}) []interface{} {
var def []interface{}

Expand All @@ -328,9 +333,10 @@ func (j *Json) MustArray(args ...[]interface{}) []interface{} {
// MustMap guarantees the return of a `map[string]interface{}` (with optional default)
//
// useful when you want to iterate over map values in a succinct manner:
// for k, v := range js.Get("dictionary").MustMap() {
// fmt.Println(k, v)
// }
//
// for k, v := range js.Get("dictionary").MustMap() {
// fmt.Println(k, v)
// }
func (j *Json) MustMap(args ...map[string]interface{}) map[string]interface{} {
var def map[string]interface{}

Expand All @@ -353,7 +359,8 @@ func (j *Json) MustMap(args ...map[string]interface{}) map[string]interface{} {
// MustString guarantees the return of a `string` (with optional default)
//
// useful when you explicitly want a `string` in a single value return context:
// myFunc(js.Get("param1").MustString(), js.Get("optional_param").MustString("my_default"))
//
// myFunc(js.Get("param1").MustString(), js.Get("optional_param").MustString("my_default"))
func (j *Json) MustString(args ...string) string {
var def string

Expand All @@ -376,9 +383,10 @@ func (j *Json) MustString(args ...string) string {
// MustStringArray guarantees the return of a `[]string` (with optional default)
//
// useful when you want to iterate over array values in a succinct manner:
// for i, s := range js.Get("results").MustStringArray() {
// fmt.Println(i, s)
// }
//
// for i, s := range js.Get("results").MustStringArray() {
// fmt.Println(i, s)
// }
func (j *Json) MustStringArray(args ...[]string) []string {
var def []string

Expand All @@ -401,7 +409,8 @@ func (j *Json) MustStringArray(args ...[]string) []string {
// MustInt guarantees the return of an `int` (with optional default)
//
// useful when you explicitly want an `int` in a single value return context:
// myFunc(js.Get("param1").MustInt(), js.Get("optional_param").MustInt(5150))
//
// myFunc(js.Get("param1").MustInt(), js.Get("optional_param").MustInt(5150))
func (j *Json) MustInt(args ...int) int {
var def int

Expand All @@ -424,7 +433,8 @@ func (j *Json) MustInt(args ...int) int {
// MustFloat64 guarantees the return of a `float64` (with optional default)
//
// useful when you explicitly want a `float64` in a single value return context:
// myFunc(js.Get("param1").MustFloat64(), js.Get("optional_param").MustFloat64(5.150))
//
// myFunc(js.Get("param1").MustFloat64(), js.Get("optional_param").MustFloat64(5.150))
func (j *Json) MustFloat64(args ...float64) float64 {
var def float64

Expand All @@ -447,7 +457,8 @@ func (j *Json) MustFloat64(args ...float64) float64 {
// MustBool guarantees the return of a `bool` (with optional default)
//
// useful when you explicitly want a `bool` in a single value return context:
// myFunc(js.Get("param1").MustBool(), js.Get("optional_param").MustBool(true))
//
// myFunc(js.Get("param1").MustBool(), js.Get("optional_param").MustBool(true))
func (j *Json) MustBool(args ...bool) bool {
var def bool

Expand All @@ -470,7 +481,8 @@ func (j *Json) MustBool(args ...bool) bool {
// MustInt64 guarantees the return of an `int64` (with optional default)
//
// useful when you explicitly want an `int64` in a single value return context:
// myFunc(js.Get("param1").MustInt64(), js.Get("optional_param").MustInt64(5150))
//
// myFunc(js.Get("param1").MustInt64(), js.Get("optional_param").MustInt64(5150))
func (j *Json) MustInt64(args ...int64) int64 {
var def int64

Expand All @@ -493,7 +505,8 @@ func (j *Json) MustInt64(args ...int64) int64 {
// MustUInt64 guarantees the return of an `uint64` (with optional default)
//
// useful when you explicitly want an `uint64` in a single value return context:
// myFunc(js.Get("param1").MustUint64(), js.Get("optional_param").MustUint64(5150))
//
// myFunc(js.Get("param1").MustUint64(), js.Get("optional_param").MustUint64(5150))
func (j *Json) MustUint64(args ...uint64) uint64 {
var def uint64

Expand Down
2 changes: 1 addition & 1 deletion pkg/expr/classic/reduce.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (cr classicReducer) ValidReduceFunc() bool {
return false
}

//nolint: gocyclo
// nolint: gocyclo
func (cr classicReducer) Reduce(series mathexp.Series) mathexp.Number {
num := mathexp.NewNumber("", nil)

Expand Down
1 change: 1 addition & 0 deletions pkg/ifaces/gcsifaces/gcsifaces.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Package gcsifaces provides interfaces for Google Cloud Storage.
//
//go:generate mockgen -source $GOFILE -destination ../../mocks/mock_gcsifaces/mocks.go StorageClient
package gcsifaces

Expand Down
2 changes: 1 addition & 1 deletion pkg/infra/filestorage/cdk_blob_filestorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func (c cdkBlobStorage) DeleteFolder(ctx context.Context, folderPath string, opt
return lastErr
}

//nolint: gocyclo
// nolint: gocyclo
func (c cdkBlobStorage) list(ctx context.Context, folderPath string, paging *Paging, options *ListOptions) (*ListResponse, error) {
lowerRootPath := strings.ToLower(folderPath)
iterators := []*blob.ListIterator{c.bucket.List(&blob.ListOptions{
Expand Down
2 changes: 1 addition & 1 deletion pkg/infra/filestorage/db_filestorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func upsertProperty(dialect migrator.Dialect, sess *sqlstore.DBSession, now time
return err
}

//nolint: gocyclo
// nolint: gocyclo
func (s dbFileStorage) List(ctx context.Context, folderPath string, paging *Paging, options *ListOptions) (*ListResponse, error) {
var resp *ListResponse

Expand Down
7 changes: 5 additions & 2 deletions pkg/infra/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,12 @@ func (cl *ConcreteLogger) New(ctx ...interface{}) *ConcreteLogger {
// name plus additional contextual information, you must use the
// Logger interface New method for it to work as expected.
// Example creating a shared logger:
// requestLogger := log.New("request-logger")
//
// requestLogger := log.New("request-logger")
//
// Example creating a contextual logger:
// contextualLogger := requestLogger.New("username", "user123")
//
// contextualLogger := requestLogger.New("username", "user123")
func New(ctx ...interface{}) *ConcreteLogger {
if len(ctx) == 0 {
return root.New()
Expand Down
5 changes: 2 additions & 3 deletions pkg/infra/log/term/terminal_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,11 @@ type terminalLogger struct {
// level output and terser human friendly timestamp.
// This format should only be used for interactive programs or while developing.
//
// [TIME] [LEVEL] MESSAGE key=value key=value ...
// [TIME] [LEVEL] MESSAGE key=value key=value ...
//
// Example:
//
// [May 16 20:58:45] [DBUG] remove route ns=haproxy addr=127.0.0.1:50002
//
// [May 16 20:58:45] [DBUG] remove route ns=haproxy addr=127.0.0.1:50002
func NewTerminalLogger(w io.Writer) gokitlog.Logger {
return &terminalLogger{w}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/infra/remotecache/remotecache.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func ProvideService(cfg *setting.Cfg, sqlStore *sqlstore.SQLStore) (*RemoteCache
// CacheStorage allows the caller to set, get and delete items in the cache.
// Cached items are stored as byte arrays and marshalled using "encoding/gob"
// so any struct added to the cache needs to be registered with `remotecache.Register`
// ex `remotecache.Register(CacheableStruct{})``
// ex `remotecache.Register(CacheableStruct{})
type CacheStorage interface {
// Get reads object from Cache
Get(ctx context.Context, key string) (interface{}, error)
Expand Down
2 changes: 0 additions & 2 deletions pkg/models/dashboard_acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ func (dto *DashboardAclInfoDTO) IsDuplicateOf(other *DashboardAclInfoDTO) bool {
return dto.hasSameRoleAs(other) || dto.hasSameUserAs(other) || dto.hasSameTeamAs(other)
}

//
// QUERIES
//
type GetDashboardAclInfoListQuery struct {
DashboardID int64
OrgID int64
Expand Down
3 changes: 2 additions & 1 deletion pkg/plugins/manager/signature/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import (
)

// Soon we can fetch keys from:
// https://grafana.com/api/plugins/ci/keys
//
// https://grafana.com/api/plugins/ci/keys
const publicKeyText = `-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: OpenPGP.js v4.10.1
Comment: https://openpgpjs.org
Expand Down
2 changes: 1 addition & 1 deletion pkg/services/accesscontrol/resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func getScopeCacheKey(orgID int64, scope string) string {
return fmt.Sprintf("%s-%v", scope, orgID)
}

//ScopeInjector inject request params into the templated scopes. e.g. "settings:" + eval.Parameters(":id")
// ScopeInjector inject request params into the templated scopes. e.g. "settings:" + eval.Parameters(":id")
func ScopeInjector(params ScopeParams) ScopeAttributeMutator {
return func(_ context.Context, scope string) ([]string, error) {
tmpl, err := template.New("scope").Parse(scope)
Expand Down
4 changes: 2 additions & 2 deletions pkg/services/alerting/conditions/query_interval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,15 @@ type fakeIntervalTestReqHandler struct {
verifier queryIntervalVerifier
}

//nolint: staticcheck // legacydata.DataResponse deprecated
// nolint: staticcheck // legacydata.DataResponse deprecated
func (rh fakeIntervalTestReqHandler) HandleRequest(ctx context.Context, dsInfo *datasources.DataSource, query legacydata.DataQuery) (
legacydata.DataResponse, error) {
q := query.Queries[0]
rh.verifier(q)
return rh.response, nil
}

//nolint: staticcheck // legacydata.DataResponse deprecated
// nolint: staticcheck // legacydata.DataResponse deprecated
func applyScenario(t *testing.T, timeRange string, dataSourceJsonData *simplejson.Json, queryModel string, verifier func(query legacydata.DataSubQuery)) {
t.Run("desc", func(t *testing.T) {
store := mockstore.NewSQLStoreMock()
Expand Down
Loading