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

Adicionado Golint como workflow #157

Merged
merged 25 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f805731
commit progress
luanc202 Jun 24, 2024
0c8caa7
feat: created test cases for breed_test with new test standards
luanc202 Jun 24, 2024
8d01873
feat: create test for breed usecase and change error formatter to str…
luanc202 Jun 28, 2024
1e5429f
refactor: rename test error case string
luanc202 Jun 28, 2024
fb9b718
feat: change update usecase tests structure to use new standard
luanc202 Jun 28, 2024
8622678
feat: change all usecase tests structure to use new standard
luanc202 Jun 28, 2024
e0cbc4e
fix: fix some broken types and expectations on tests
luanc202 Jun 28, 2024
a7d8249
Merge branch 'main' into issue148
luanc202 Jun 28, 2024
3924cba
fix: repeated function definitions
luanc202 Jun 28, 2024
3bb8db3
fix: function returning struct instead of struct pointer
luanc202 Jun 28, 2024
136854f
feat: create golang linter ci
luanc202 Jul 5, 2024
182843a
feat: add golint workflow
luanc202 Jul 10, 2024
08d0f38
Merge branch 'issue-155' of github.com:luanc202/pet-dex-backend into …
luanc202 Jul 10, 2024
3a4ae72
feat: add missing usecase
luanc202 Jul 10, 2024
eeab002
feat: remove master branch from trigger, added workflow_dispatch to e…
luanc202 Jul 15, 2024
48b7739
Merge branch 'issue-155' of github.com:luanc202/pet-dex-backend into …
luanc202 Jul 15, 2024
7e4aef2
Merge branch 'main' into issue-155
luanc202 Jul 15, 2024
9e662bb
fix: fix golanglint errors
luanc202 Jul 18, 2024
c2c3d61
Merge branch 'issue148' into issue-155
luanc202 Jul 18, 2024
d77df5d
Merge branch 'issue-155' of github.com:luanc202/pet-dex-backend into …
luanc202 Jul 18, 2024
3416e7c
fix: comment unused lines due to golint complaining
luanc202 Jul 18, 2024
85838fa
fix: fix new linter issues
luanc202 Jul 18, 2024
c448336
feat: add linter command to Makefile
luanc202 Jul 18, 2024
95ffe6b
fix lint command error
luanc202 Jul 18, 2024
2e18ad9
feat: specify workflow for pull requests on main only
luanc202 Jul 18, 2024
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
44 changes: 44 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: golangci-lint

on:
luanc202 marked this conversation as resolved.
Show resolved Hide resolved
pull_request:
luanc202 marked this conversation as resolved.
Show resolved Hide resolved
branches:
- "main"
push:
branches:
- "main"
workflow_dispatch:

env:
GO_VERSION: stable
GOLANGCI_LINT_VERSION: v1.59

jobs:
detect-modules:
zoldyzdk marked this conversation as resolved.
Show resolved Hide resolved
runs-on: ubuntu-latest
outputs:
modules: ${{ steps.set-modules.outputs.modules }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- id: set-modules
run: echo "modules=$(go list -m -json | jq -s '.' | jq -c '[.[].Dir]')" >> $GITHUB_OUTPUT

golangci-lint:
needs: detect-modules
runs-on: ubuntu-latest
strategy:
matrix:
modules: ${{ fromJSON(needs.detect-modules.outputs.modules) }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: golangci-lint ${{ matrix.modules }}
uses: golangci/golangci-lint-action@v6
with:
version: ${{ env.GOLANGCI_LINT_VERSION }}
working-directory: ${{ matrix.modules }}
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ migration:

migration-up:
go run cmd/main.go -up

lint:
docker run --rm -v ./:/app -w /app golangci/golangci-lint:v1.59.1 golangci-lint run -v
6 changes: 5 additions & 1 deletion api/controllers/breed.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ func (cntrl *BreedController) List(responseWriter http.ResponseWriter, request *
}

responseWriter.WriteHeader(http.StatusOK)
json.NewEncoder(responseWriter).Encode(breeds)
err = json.NewEncoder(responseWriter).Encode(breeds)
if err != nil {
logger.Error("error encoding json", err)
responseWriter.WriteHeader(http.StatusInternalServerError)
}
}

func (cntrl *BreedController) FindBreed(w http.ResponseWriter, r *http.Request) {
Expand Down
16 changes: 10 additions & 6 deletions api/controllers/ong.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (oc *OngController) Insert(w http.ResponseWriter, r *http.Request) {


func (oc *OngController) List(w http.ResponseWriter, r *http.Request) {
pageStr := r.URL.Query().Get("page")
// pageStr := r.URL.Query().Get("page")
limitStr := r.URL.Query().Get("limit")
sortBy := r.URL.Query().Get("sortBy")
order := r.URL.Query().Get("order")
Expand All @@ -63,10 +63,10 @@ func (oc *OngController) List(w http.ResponseWriter, r *http.Request) {
order = "asc"
}

page, err := strconv.Atoi(pageStr)
if err != nil || page < 1 {
page = 1
}
// page, err := strconv.Atoi(pageStr)
// if err != nil || page < 1 {
// page = 1
// }

limit, err := strconv.Atoi(limitStr)
if err != nil || limit < 1 {
Expand All @@ -84,7 +84,11 @@ func (oc *OngController) List(w http.ResponseWriter, r *http.Request) {
}

w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(ongs)
err = json.NewEncoder(w).Encode(ongs)
if err != nil {
logger.Error("error encoding json", err)
w.WriteHeader(http.StatusInternalServerError)
}
}

func (oc *OngController) FindByID(w http.ResponseWriter, r *http.Request) {
Expand Down
31 changes: 25 additions & 6 deletions api/controllers/pet.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ func (pc *PetController) Update(w http.ResponseWriter, r *http.Request) {
}

w.WriteHeader(http.StatusBadRequest)
json.NewEncoder(w).Encode(err)
return
json_err := json.NewEncoder(w).Encode(err)
if json_err != nil {
logger.Error("error encoding json", err)
w.WriteHeader(http.StatusInternalServerError)
}
}

err = pc.Usecase.Update(petID, userID, petUpdateDto)
Expand All @@ -58,7 +61,11 @@ func (pc *PetController) Update(w http.ResponseWriter, r *http.Request) {
}

w.WriteHeader(http.StatusBadRequest)
json.NewEncoder(w).Encode(err)
json_err := json.NewEncoder(w).Encode(err)
if json_err != nil {
logger.Error("error encoding json", err)
w.WriteHeader(http.StatusInternalServerError)
}
return
}
}
Expand Down Expand Up @@ -119,9 +126,13 @@ func (cntrl *PetController) CreatePet(w http.ResponseWriter, r *http.Request) {
fmt.Printf("Invalid request: could not decode pet data from request body %s", err.Error())

w.WriteHeader(http.StatusBadRequest)
json.NewEncoder(w).Encode(errors.ErrInvalidBody{
json_err := json.NewEncoder(w).Encode(errors.ErrInvalidBody{
Description: "The body is invalid",
})
if json_err != nil {
logger.Error("error encoding json", err)
w.WriteHeader(http.StatusInternalServerError)
}
return
}

Expand All @@ -130,7 +141,11 @@ func (cntrl *PetController) CreatePet(w http.ResponseWriter, r *http.Request) {
fmt.Printf("Invalid request: could not validate pet data from request body %s", err.Error())

w.WriteHeader(http.StatusBadRequest)
json.NewEncoder(w).Encode(err)
json_err := json.NewEncoder(w).Encode(err)
if json_err != nil {
logger.Error("error encoding json", err)
w.WriteHeader(http.StatusInternalServerError)
}
return
}

Expand All @@ -142,7 +157,11 @@ func (cntrl *PetController) CreatePet(w http.ResponseWriter, r *http.Request) {
err := err.Error()

w.WriteHeader(http.StatusBadRequest)
json.NewEncoder(w).Encode(err)
json_err := json.NewEncoder(w).Encode(err)
if json_err != nil {
logger.Error("error encoding json", err)
w.WriteHeader(http.StatusInternalServerError)
}
return
}

Expand Down
7 changes: 6 additions & 1 deletion api/controllers/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,16 @@ func (uc *UserController) GenerateToken(w http.ResponseWriter, r *http.Request)
http.Error(w, err.Error(), http.StatusBadRequest)
}
w.Header().Add("Authorization", token)
json.NewEncoder(w).Encode(struct {
json_err := json.NewEncoder(w).Encode(struct {
Token string `json:"token"`
}{
Token: token,
})
if json_err != nil {
logger.Error("error encoding json", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
w.WriteHeader(201)
}

Expand Down
6 changes: 5 additions & 1 deletion api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ func main() {
panic(err)
}

config.InitConfigs()
err = config.InitConfigs()
if err != nil {
panic(err)
}

sqlxDb, err := sqlx.Open("mysql", env.DBUrl)

if err != nil {
Expand Down
Loading