Skip to content

Commit 8d6c556

Browse files
committed
chore(golangci-lint): refactor all code with golangci-lint
use `golangci-lint run --fix` to autofix explict lint error
1 parent 99827ad commit 8d6c556

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+235
-239
lines changed

api/apps.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import (
1414
"strings"
1515
)
1616

17-
func structToFlatMap(obj interface{}) map[string]interface{} {
18-
result := make(map[string]interface{})
17+
func structToFlatMap(obj any) map[string]any {
18+
result := make(map[string]any)
1919
val := reflect.ValueOf(obj)
2020
typ := reflect.TypeOf(obj)
2121

@@ -137,7 +137,7 @@ func deleteApp(w http.ResponseWriter, r *http.Request) {
137137
w.WriteHeader(http.StatusNoContent)
138138
}
139139

140-
func setAppOption(store db.Store, appID string, field string, val interface{}) error {
140+
func setAppOption(store db.Store, appID string, field string, val any) error {
141141
key := "apps." + appID + "." + field
142142

143143
if val == nil {

api/auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func getSession(r *http.Request) (*db.Session, bool) {
2222
return nil, false
2323
}
2424

25-
value := make(map[string]interface{})
25+
value := make(map[string]any)
2626
if err = util.Cookie.Decode("semaphore", cookie.Value, &value); err != nil {
2727
//w.WriteHeader(http.StatusUnauthorized)
2828
return nil, false

api/helpers/context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package helpers
33
import (
44
"net/http"
55

6-
"github.com/semaphoreui/semaphore/db"
76
"github.com/gorilla/context"
7+
"github.com/semaphoreui/semaphore/db"
88
)
99

1010
func UserFromContext(r *http.Request) *db.User {

api/helpers/helpers.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ func GetIntParam(name string, w http.ResponseWriter, r *http.Request) (int, erro
7171
}
7272

7373
// H just a string-to-anything map
74-
type H map[string]interface{}
74+
type H map[string]any
7575

7676
// Bind decodes json into object
77-
func Bind(w http.ResponseWriter, r *http.Request, out interface{}) bool {
77+
func Bind(w http.ResponseWriter, r *http.Request, out any) bool {
7878
err := json.NewDecoder(r.Body).Decode(out)
7979
if err != nil {
8080
w.WriteHeader(http.StatusBadRequest)
@@ -84,7 +84,7 @@ func Bind(w http.ResponseWriter, r *http.Request, out interface{}) bool {
8484
}
8585

8686
// WriteJSON writes object as JSON
87-
func WriteJSON(w http.ResponseWriter, code int, out interface{}) {
87+
func WriteJSON(w http.ResponseWriter, code int, out any) {
8888
w.Header().Set("content-type", "application/json")
8989
w.WriteHeader(code)
9090

api/integration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func Match(matcher db.IntegrationMatcher, header http.Header, bodyBytes []byte)
217217
return false
218218
}
219219

220-
func MatchCompare(value interface{}, method db.IntegrationMatchMethodType, expected string) bool {
220+
func MatchCompare(value any, method db.IntegrationMatchMethodType, expected string) bool {
221221

222222
if intValue, ok := conv.ConvertFloatToIntIfPossible(value); ok {
223223
value = intValue

api/login.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func createSession(w http.ResponseWriter, r *http.Request, user db.User) {
177177
return
178178
}
179179

180-
encoded, err := util.Cookie.Encode("semaphore", map[string]interface{}{
180+
encoded, err := util.Cookie.Encode("semaphore", map[string]any{
181181
"user": user.ID,
182182
"session": newSession.ID,
183183
})
@@ -542,17 +542,17 @@ func parseClaim(str string, claims map[string]any) (string, bool) {
542542
return "", false
543543
}
544544

545-
func prepareClaims(claims map[string]interface{}) {
545+
func prepareClaims(claims map[string]any) {
546546
for k, v := range claims {
547-
switch v.(type) {
547+
switch v := v.(type) {
548548
case float64:
549-
f := v.(float64)
549+
f := v
550550
i := int64(f)
551551
if float64(i) == f {
552552
claims[k] = i
553553
}
554554
case float32:
555-
f := v.(float32)
555+
f := v
556556
i := int64(f)
557557
if float32(i) == f {
558558
claims[k] = i
@@ -584,7 +584,7 @@ func parseClaims(claims map[string]any, provider util.ClaimsProvider) (res claim
584584
}
585585

586586
func claimOidcUserInfo(userInfo *oidc.UserInfo, provider util.OidcProvider) (res claimResult, err error) {
587-
claims := make(map[string]interface{})
587+
claims := make(map[string]any)
588588
if err = userInfo.Claims(&claims); err != nil {
589589
return
590590
}
@@ -595,7 +595,7 @@ func claimOidcUserInfo(userInfo *oidc.UserInfo, provider util.OidcProvider) (res
595595
}
596596

597597
func claimOidcToken(idToken *oidc.IDToken, provider util.OidcProvider) (res claimResult, err error) {
598-
claims := make(map[string]interface{})
598+
claims := make(map[string]any)
599599
if err = idToken.Claims(&claims); err != nil {
600600
return
601601
}

api/login_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
)
66

77
func TestParseClaim(t *testing.T) {
8-
claims := map[string]interface{}{
8+
claims := map[string]any{
99
"username": "fiftin",
1010
"email": "",
1111
"id": 1234567,
@@ -23,7 +23,7 @@ func TestParseClaim(t *testing.T) {
2323
}
2424

2525
func TestParseClaim2(t *testing.T) {
26-
claims := map[string]interface{}{
26+
claims := map[string]any{
2727
"username": "fiftin",
2828
"email": "",
2929
"id": 1234567,
@@ -41,7 +41,7 @@ func TestParseClaim2(t *testing.T) {
4141
}
4242

4343
func TestParseClaim3(t *testing.T) {
44-
claims := map[string]interface{}{
44+
claims := map[string]any{
4545
"username": "fiftin",
4646
"email": "",
4747
"id": 1234567,
@@ -55,7 +55,7 @@ func TestParseClaim3(t *testing.T) {
5555
}
5656

5757
func TestParseClaim4(t *testing.T) {
58-
claims := map[string]interface{}{
58+
claims := map[string]any{
5959
"username": "fiftin",
6060
"email": "",
6161
"id": 1234567,
@@ -69,7 +69,7 @@ func TestParseClaim4(t *testing.T) {
6969
}
7070

7171
func TestParseClaim5(t *testing.T) {
72-
claims := map[string]interface{}{
72+
claims := map[string]any{
7373
"username": "fiftin",
7474
"email": "",
7575
"id": 123456757343.0,

api/options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package api
22

33
import (
4+
"github.com/gorilla/context"
45
"github.com/semaphoreui/semaphore/api/helpers"
56
"github.com/semaphoreui/semaphore/db"
6-
"github.com/gorilla/context"
77
"net/http"
88
)
99

api/projects/backup_restore.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import (
55
"net/http"
66
"strings"
77

8+
"github.com/gorilla/context"
89
"github.com/semaphoreui/semaphore/api/helpers"
910
"github.com/semaphoreui/semaphore/db"
1011
projectService "github.com/semaphoreui/semaphore/services/project"
11-
"github.com/gorilla/context"
1212
log "github.com/sirupsen/logrus"
1313
)
1414

api/projects/environment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func RemoveEnvironment(w http.ResponseWriter, r *http.Request) {
222222

223223
err := helpers.Store(r).DeleteEnvironment(env.ProjectID, env.ID)
224224
if err == db.ErrInvalidOperation {
225-
helpers.WriteJSON(w, http.StatusBadRequest, map[string]interface{}{
225+
helpers.WriteJSON(w, http.StatusBadRequest, map[string]any{
226226
"error": "Environment is in use by one or more templates",
227227
"inUse": true,
228228
})

0 commit comments

Comments
 (0)