Skip to content

Commit

Permalink
lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Raajheer1 committed Aug 25, 2024
1 parent bd10d42 commit 44eaf77
Show file tree
Hide file tree
Showing 20 changed files with 40 additions and 93 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ jobs:
- name: Setup go
uses: actions/setup-go@v5
with:
go-version: 1.22.1
go-version: 1.23.0
- name: Run linters
uses: golangci/golangci-lint-action@v4
with:
version: v1.56.2
version: v1.60.3
args: --timeout=5m
58 changes: 21 additions & 37 deletions cmd/api/external/main_tls.go
Original file line number Diff line number Diff line change
@@ -1,39 +1,23 @@
package main

import (
"fmt"
"github.com/VATUSA/primary-api/external"
"github.com/VATUSA/primary-api/pkg/config"
"github.com/VATUSA/primary-api/pkg/cookie"
"github.com/VATUSA/primary-api/pkg/database"
"github.com/VATUSA/primary-api/pkg/database/models"
gochi "github.com/VATUSA/primary-api/pkg/go-chi"
"github.com/VATUSA/primary-api/pkg/logger"
"github.com/VATUSA/primary-api/pkg/oauth"
"github.com/VATUSA/primary-api/pkg/storage"
"github.com/joho/godotenv"
"log"
"net/http"
)

func main() {
_ = godotenv.Load(".env")
config.Cfg = config.New()

oauth.OAuthConfig = oauth.Initialize(config.Cfg)

bucket, err := storage.NewS3Client(config.Cfg.S3)
if err != nil {
panic(err)
}

storage.PublicBucket = bucket
database.DB = database.Connect(config.Cfg.Database)
cookie.CookieStore = cookie.New(config.Cfg)
models.AutoMigrate()
logger.Setup()

r := gochi.New(config.Cfg)
external.Router(r, config.Cfg)
log.Fatalf("Err starting http server: %s", http.ListenAndServeTLS(fmt.Sprintf(":%s", config.Cfg.API.Port), "./api.vatusa.local.crt", "./api.vatusa.local.key", r))
}
//func main() {
// _ = godotenv.Load(".env")
// config.Cfg = config.New()
//
// oauth.OAuthConfig = oauth.Initialize(config.Cfg)
//
// bucket, err := storage.NewS3Client(config.Cfg.S3)
// if err != nil {
// panic(err)
// }
//
// storage.PublicBucket = bucket
// database.DB = database.Connect(config.Cfg.Database)
// cookie.CookieStore = cookie.New(config.Cfg)
// models.AutoMigrate()
// logger.Setup()
//
// r := gochi.New(config.Cfg)
// external.Router(r, config.Cfg)
// log.Fatalf("Err starting http server: %s", http.ListenAndServeTLS(fmt.Sprintf(":%s", config.Cfg.API.Port), "./api.vatusa.local.crt", "./api.vatusa.local.key", r))
//}
6 changes: 3 additions & 3 deletions external/v3/action-log/action_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func CreateActionLogEntry(w http.ResponseWriter, r *http.Request) {

createdBy := ""
if self := utils.GetXUser(r); self != nil {
createdBy = fmt.Sprintf("%d", self)
createdBy = fmt.Sprintf("%d", self.CID)
} else {
createdBy = string(utils.GetXFacility(r).ID)
}
Expand Down Expand Up @@ -152,7 +152,7 @@ func UpdateActionLogEntry(w http.ResponseWriter, r *http.Request) {
ale.Entry = data.Entry

if self := utils.GetXUser(r); self != nil {
ale.UpdatedBy = fmt.Sprintf("%d", self)
ale.UpdatedBy = fmt.Sprintf("%d", self.CID)
} else {
ale.UpdatedBy = string(utils.GetXFacility(r).ID)
}
Expand Down Expand Up @@ -193,7 +193,7 @@ func PatchActionLogEntry(w http.ResponseWriter, r *http.Request) {
}

if self := utils.GetXUser(r); self != nil {
ale.UpdatedBy = fmt.Sprintf("%d", self)
ale.UpdatedBy = fmt.Sprintf("%d", self.CID)
} else {
ale.UpdatedBy = string(utils.GetXFacility(r).ID)
}
Expand Down
6 changes: 3 additions & 3 deletions external/v3/disciplinary-log/disciplinary_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func CreateDisciplinaryLogEntry(w http.ResponseWriter, r *http.Request) {

createdBy := ""
if self := utils.GetXUser(r); self != nil {
createdBy = fmt.Sprintf("%d", self)
createdBy = fmt.Sprintf("%d", self.CID)
} else {
createdBy = string(utils.GetXFacility(r).ID)
}
Expand Down Expand Up @@ -158,7 +158,7 @@ func UpdateDisciplinaryLogEntry(w http.ResponseWriter, r *http.Request) {
dle.VATUSAOnly = data.VATUSAOnly

if self := utils.GetXUser(r); self != nil {
dle.UpdatedBy = fmt.Sprintf("%d", self)
dle.UpdatedBy = fmt.Sprintf("%d", self.CID)
} else {
dle.UpdatedBy = string(utils.GetXFacility(r).ID)
}
Expand Down Expand Up @@ -202,7 +202,7 @@ func PatchDisciplinaryLogEntry(w http.ResponseWriter, r *http.Request) {
}

if self := utils.GetXUser(r); self != nil {
dle.UpdatedBy = fmt.Sprintf("%d", self)
dle.UpdatedBy = fmt.Sprintf("%d", self.CID)
} else {
dle.UpdatedBy = string(utils.GetXFacility(r).ID)
}
Expand Down
6 changes: 3 additions & 3 deletions external/v3/facility-log/facility_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func CreateFacilityLogEntry(w http.ResponseWriter, r *http.Request) {

createdBy := ""
if self := utils.GetXUser(r); self != nil {
createdBy = fmt.Sprintf("%d", self)
createdBy = fmt.Sprintf("%d", self.CID)
} else {
createdBy = string(utils.GetXFacility(r).ID)
}
Expand Down Expand Up @@ -161,7 +161,7 @@ func UpdateFacilityLog(w http.ResponseWriter, r *http.Request) {
fle.Entry = data.Entry

if self := utils.GetXUser(r); self != nil {
fle.UpdatedBy = fmt.Sprintf("%d", self)
fle.UpdatedBy = fmt.Sprintf("%d", self.CID)
} else {
fle.UpdatedBy = string(utils.GetXFacility(r).ID)
}
Expand Down Expand Up @@ -210,7 +210,7 @@ func PatchFacilityLog(w http.ResponseWriter, r *http.Request) {
}

if self := utils.GetXUser(r); self != nil {
fle.UpdatedBy = fmt.Sprintf("%d", self)
fle.UpdatedBy = fmt.Sprintf("%d", self.CID)
} else {
fle.UpdatedBy = string(utils.GetXFacility(r).ID)
}
Expand Down
7 changes: 2 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ require (
github.com/gorilla/securecookie v1.1.2
github.com/joho/godotenv v1.5.1
github.com/matoous/go-nanoid v1.5.0
github.com/sirupsen/logrus v1.9.3
github.com/swaggo/http-swagger v1.3.4
github.com/swaggo/swag v1.16.3
go.uber.org/zap v1.27.0
golang.org/x/oauth2 v0.19.0
gorm.io/driver/mysql v1.5.6
gorm.io/gorm v1.25.9
Expand Down Expand Up @@ -46,13 +48,8 @@ require (
github.com/josharian/intern v1.0.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/rs/zerolog v1.33.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/swaggo/files v1.0.1 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sys v0.24.0 // indirect
Expand Down
21 changes: 2 additions & 19 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ github.com/aws/aws-sdk-go-v2/service/s3 v1.53.1 h1:6cnno47Me9bRykw9AEv9zkXE+5or7
github.com/aws/aws-sdk-go-v2/service/s3 v1.53.1/go.mod h1:qmdkIIAC+GCLASF7R2whgNrJADz0QZPX+Seiw/i4S3o=
github.com/aws/smithy-go v1.20.2 h1:tbp628ireGtzcHDDmLT/6ADHidqnwgF57XOXZe6tp4Q=
github.com/aws/smithy-go v1.20.2/go.mod h1:krry+ya/rV9RDcV/Q16kpu6ypI4K2czasz0NC3qS14E=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -59,7 +58,6 @@ github.com/go-playground/validator/v10 v10.19.0/go.mod h1:dbuPbCMFw/DrkbEynArYaC
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
Expand All @@ -84,20 +82,10 @@ github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/matoous/go-nanoid v1.5.0 h1:VRorl6uCngneC4oUQqOYtO3S0H5QKFtKuKycFG3euek=
github.com/matoous/go-nanoid v1.5.0/go.mod h1:zyD2a71IubI24efhpvkJz+ZwfwagzgSO6UNiFsZKN7U=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand All @@ -111,6 +99,8 @@ github.com/swaggo/http-swagger v1.3.4/go.mod h1:9dAh0unqMBAlbp1uE2Uc2mQTxNMU/ha4
github.com/swaggo/swag v1.16.3 h1:PnCYjPCah8FK4I26l2F/KQ4yz3sILcVUN3cTlBFA9Pg=
github.com/swaggo/swag v1.16.3/go.mod h1:DImHIuOFXKpMFAQjcC7FG4m3Dg4+QuUgUzJmKjI/gRk=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
Expand Down Expand Up @@ -140,14 +130,7 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
Expand Down
2 changes: 0 additions & 2 deletions pkg/go-chi/middleware/auth/action_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func CanReadActionLog(next http.Handler) http.Handler {
}

utils.Render(w, r, utils.ErrForbidden)
return
})
}

Expand All @@ -59,6 +58,5 @@ func CanEditActionLog(next http.Handler) http.Handler {
}

utils.Render(w, r, utils.ErrForbidden)
return
})
}
2 changes: 0 additions & 2 deletions pkg/go-chi/middleware/auth/disciplinary_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func CanReadDisciplinaryLog(next http.Handler) http.Handler {
}
}
utils.Render(w, r, utils.ErrForbidden)
return
})
}

Expand All @@ -69,6 +68,5 @@ func CanEditDisciplinaryLog(next http.Handler) http.Handler {
log.Warnf("User %d, attempted to edit disciplinary log for user: %d. No permissions.", credentials.User.CID, targetUser.CID)

utils.Render(w, r, utils.ErrForbidden)
return
})
}
1 change: 0 additions & 1 deletion pkg/go-chi/middleware/auth/facility.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,5 @@ func CanEditFacility(next http.Handler) http.Handler {
}

utils.Render(w, r, utils.ErrForbidden)
return
})
}
2 changes: 0 additions & 2 deletions pkg/go-chi/middleware/auth/facility_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func CanViewFacilityLog(next http.Handler) http.Handler {
}

utils.Render(w, r, utils.ErrForbidden)
return
})
}

Expand All @@ -54,6 +53,5 @@ func CanEditFacilityLog(next http.Handler) http.Handler {
}

utils.Render(w, r, utils.ErrForbidden)
return
})
}
1 change: 0 additions & 1 deletion pkg/go-chi/middleware/auth/faq.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,5 @@ func CanEditFAQ(next http.Handler) http.Handler {
}

utils.Render(w, r, utils.ErrForbidden)
return
})
}
7 changes: 4 additions & 3 deletions pkg/go-chi/middleware/auth/feedback.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ func CanViewFeedback(next http.Handler) http.Handler {
}

if credentials.User.CID == uint(cidInt) {
r.URL.Query().Set("status", "accepted")
q := r.URL.Query()
q.Set("cid", cid) // Preserve the original 'cid'
q.Set("status", "accepted") // Set the 'status' to 'accepted'
r.URL.RawQuery = q.Encode()
next.ServeHTTP(w, r)
return
}
Expand All @@ -52,7 +55,6 @@ func CanViewFeedback(next http.Handler) http.Handler {
}

utils.Render(w, r, utils.ErrForbidden)
return
})
}

Expand Down Expand Up @@ -86,6 +88,5 @@ func CanEditFeedback(next http.Handler) http.Handler {
}

utils.Render(w, r, utils.ErrForbidden)
return
})
}
1 change: 0 additions & 1 deletion pkg/go-chi/middleware/auth/news.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,5 @@ func CanEditNews(next http.Handler) http.Handler {
}

utils.Render(w, r, utils.ErrForbidden)
return
})
}
2 changes: 0 additions & 2 deletions pkg/go-chi/middleware/auth/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func CanViewNotifications(next http.Handler) http.Handler {
}

utils.Render(w, r, utils.ErrForbidden)
return
})
}

Expand All @@ -45,6 +44,5 @@ func CanEditNotifications(next http.Handler) http.Handler {
}

utils.Render(w, r, utils.ErrForbidden)
return
})
}
1 change: 0 additions & 1 deletion pkg/go-chi/middleware/auth/rating-change.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func CanViewRatingChange(next http.Handler) http.Handler {
}

utils.Render(w, r, utils.ErrForbidden)
return
})
}

Expand Down
1 change: 0 additions & 1 deletion pkg/go-chi/middleware/auth/roster.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,5 @@ func CanEditRoster(next http.Handler) http.Handler {
}

utils.Render(w, r, utils.ErrForbidden)
return
})
}
1 change: 0 additions & 1 deletion pkg/go-chi/middleware/auth/roster_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,5 @@ func CanEditRosterRequest(next http.Handler) http.Handler {
}

utils.Render(w, r, utils.ErrForbidden)
return
})
}
2 changes: 0 additions & 2 deletions pkg/go-chi/middleware/auth/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ func CanViewUser(next http.Handler) http.Handler {
}

utils.Render(w, r, utils.ErrForbidden)
return
})
}

Expand All @@ -58,6 +57,5 @@ func CanEditUser(next http.Handler) http.Handler {
}

utils.Render(w, r, utils.ErrForbidden)
return
})
}
Loading

0 comments on commit 44eaf77

Please sign in to comment.