diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..de72be5 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,28 @@ +name: Project Linting + +on: + push: + branches: + - '**' + +jobs: + lint: + name: Run golangci-lint + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.22' + + - name: Install golangci-lint + run: | + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.54.2 + + - name: Run golangci-lint + run: | + golangci-lint run diff --git a/.gitignore b/.gitignore index 1fb9ef5..bd1bd3a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ tmp/* +TODO.md diff --git a/README.md b/README.md index 52e09f1..89e8c74 100644 --- a/README.md +++ b/README.md @@ -87,44 +87,5 @@ Will place the controller template structure here when I've built the template f ### Services Will place the service template structure here when I've built the template file. ---- - -Current Dev tasks -straight coding tasks: -- [x] dockerfile written -- [x] docker compose together -- [x] setup connection between postgres and backend using gorm -- [x] basic user model to test jwt auth -- [x] connected Air to have hot reloading during development -- [x] signing jwt access and refresh tokens -- [x] writing the authentication middleware -- [x] roles for users -- [x] refresh access token -- [x] middleware auth for multiple roles -- [ ] Rate limiting? -- [ ] only https traffic -- [ ] setup CORS (Cross Origin Resource Sharing) -- [ ] possible look into CSRF (Cross Site Request Forgery) -- [ ] setup swagger api documentation -- [ ] possibly some sort of health checks (not sure what to really do here) -- [ ] setup a query caching example -- [ ] background job queue?? (not sure if this fits here...) -- [ ] better api versioning (put a system in place) -- [ ] figure out how to serve static files (will need a cdn (content delivery network) for that) -- [ ] rate limiting? -- [ ] figure out how unit tests -- [ ] write the runner for the automated unit tests - -coding but still vague -- [ ] write the service & controller template we will use for each part of the project - -research -- [ ] doing some additional research on bcrypt cost (i’m a little worried about it) - -doco -- [x] writing a quickstart guide -- [ ] writing doco for all of this - -possibly... -- [ ] middleware logging for all requests (ISO9001, ISO27001) -- [ ] metadata that is attached with calls (100% needed just need to think about it a bit more) db column +## Testing the Project +Linting is done using `golangci-lint run`, which will show all the errors in the project. There is also an action runner that will do the same, but ideally the linting should be run locally first before the runner has to pick it up. diff --git a/initialize/sync-database.go b/initialize/sync-database.go index cc46009..3a9a4ea 100644 --- a/initialize/sync-database.go +++ b/initialize/sync-database.go @@ -4,5 +4,8 @@ import "github.com/MountVesuvius/go-gin-postgres-template/models" // Auto migrate the table func SyncDatabase() { - DB.AutoMigrate(&models.User{}) + err := DB.AutoMigrate(&models.User{}) + if err != nil { + panic("Failed to sync the database") + } } diff --git a/main.go b/main.go index 80035bb..8db4d9d 100644 --- a/main.go +++ b/main.go @@ -32,5 +32,9 @@ func main() { router := gin.Default() routes.User(router, userController, jwtService) routes.Auth(router, jwtService) - router.Run() + + routerErr := router.Run() + if routerErr != nil { + log.Fatal("Router has not started", err) + } }