Skip to content

Commit 703f432

Browse files
committed
Add github workflows
1 parent c638fa2 commit 703f432

File tree

8 files changed

+1352
-101
lines changed

8 files changed

+1352
-101
lines changed

.github/workflows/check.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
on:
2+
push:
3+
branches: [ master ]
4+
5+
jobs:
6+
test:
7+
name: test
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v2
11+
- name: Set up Go
12+
uses: actions/setup-go@v2
13+
with:
14+
go-version: 1.16
15+
- name: Test
16+
run: make test
17+
lint:
18+
name: lint
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Check out code into the Go module directory
22+
uses: actions/checkout@v2
23+
- name: Set up Go
24+
uses: actions/setup-go@v2
25+
with:
26+
go-version: '1.14'
27+
- name: golangci-lint
28+
uses: reviewdog/action-golangci-lint@v1

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
![workflow](https://github.com/zacscoding/gin-rest-api-example/actions/workflows/check.yaml/badge.svg)
2+
13
# Rest API with golang and gin, gorm
24
This project is an exemplary rest api server built with Go :)
35

go.mod

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@ go 1.14
44

55
require (
66
github.com/appleboy/gin-jwt/v2 v2.6.4
7-
github.com/docker/distribution v2.7.1+incompatible // indirect
8-
github.com/docker/docker v1.13.1 // indirect
7+
github.com/containerd/containerd v1.6.6 // indirect
98
github.com/gin-gonic/gin v1.6.3
109
github.com/go-playground/validator/v10 v10.2.0
11-
github.com/go-sql-driver/mysql v1.5.0
10+
github.com/go-sql-driver/mysql v1.6.0
1211
github.com/golang-migrate/migrate v3.5.4+incompatible
13-
github.com/google/uuid v1.1.2
12+
github.com/google/uuid v1.2.0
13+
github.com/gorilla/mux v1.8.0 // indirect
1414
github.com/gosimple/slug v1.9.0
1515
github.com/knadh/koanf v0.13.0
16-
github.com/magiconair/properties v1.8.0
17-
github.com/ory/dockertest/v3 v3.6.0
18-
github.com/pkg/errors v0.8.1
19-
github.com/prometheus/client_golang v0.9.3
20-
github.com/spf13/cobra v1.0.0
21-
github.com/stretchr/testify v1.5.1
16+
github.com/magiconair/properties v1.8.1
17+
github.com/ory/dockertest/v3 v3.9.1
18+
github.com/pkg/errors v0.9.1
19+
github.com/prometheus/client_golang v1.11.1
20+
github.com/spf13/cobra v1.1.3
21+
github.com/stretchr/testify v1.7.1
2222
github.com/tidwall/gjson v1.6.0
2323
go.uber.org/fx v1.13.1
24-
go.uber.org/zap v1.16.0
25-
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529
24+
go.uber.org/zap v1.17.0
25+
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5
2626
gorm.io/driver/mysql v1.0.1
2727
gorm.io/gorm v1.20.0
2828
)

go.sum

Lines changed: 1294 additions & 65 deletions
Large diffs are not rendered by default.

internal/config/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func TestLoad(t *testing.T) {
2323
// db configs
2424
assert.Equal(t, defaultConfig["db.dataSourceName"].(string), cfg.DBConfig.DataSourceName)
2525
assert.Equal(t, defaultConfig["db.migrate.enable"].(bool), cfg.DBConfig.Migrate.Enable)
26-
assert.Equal(t, defaultConfig["db.migrate.dir"].(bool), cfg.DBConfig.Migrate.Dir)
26+
assert.Equal(t, defaultConfig["db.migrate.dir"].(string), cfg.DBConfig.Migrate.Dir)
2727
assert.Equal(t, defaultConfig["db.pool.maxOpen"].(int), cfg.DBConfig.Pool.MaxOpen)
2828
assert.Equal(t, defaultConfig["db.pool.maxIdle"].(int), cfg.DBConfig.Pool.MaxIdle)
2929
assert.Equal(t, defaultConfig["db.pool.maxLifetime"].(int), cfg.DBConfig.Pool.MaxLifetime)

internal/database/database_util.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@ import (
44
"database/sql"
55
"errors"
66
"fmt"
7+
"log"
8+
"os"
9+
"path/filepath"
10+
"runtime"
11+
"testing"
12+
"time"
13+
714
_ "github.com/go-sql-driver/mysql"
815
"github.com/golang-migrate/migrate"
916
"github.com/golang-migrate/migrate/database/mysql"
1017
_ "github.com/golang-migrate/migrate/source/file"
1118
gMysql "gorm.io/driver/mysql"
1219
"gorm.io/gorm"
1320
"gorm.io/gorm/logger"
14-
"log"
15-
"os"
16-
"path/filepath"
17-
"runtime"
18-
"testing"
19-
"time"
2021

2122
"github.com/ory/dockertest/v3"
2223
)
@@ -35,9 +36,14 @@ func NewTestDatabase(tb testing.TB, migration bool) *gorm.DB {
3536
}
3637

3738
// pulls an image, creates a container based on it and runs it
38-
resource, err := pool.Run("mysql", "8.0.17", []string{"MYSQL_ROOT_PASSWORD=secret"})
39+
resource, err := pool.RunWithOptions(&dockertest.RunOptions{
40+
//Platform: "linux/x86_64",
41+
Repository: "mysql",
42+
Tag: "8.0.29",
43+
Env: []string{"MYSQL_ROOT_PASSWORD=secret"},
44+
})
3945
if err != nil {
40-
tb.Fatalf("Failed to not start resource: %v", err)
46+
tb.Fatalf("Failed to start resource: %v", err)
4147
}
4248
err = resource.Expire(60 * 5)
4349

internal/database/database_util_test.go

Lines changed: 0 additions & 14 deletions
This file was deleted.

internal/middleware/handler/handler_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func TestHandleRequest(t *testing.T) {
5555
Body: `
5656
{
5757
"code": "InternalServerError",
58-
"message": "[InternalServerError]"
58+
"message": "[InternalServerError] An error has occurred, please try again later"
5959
}
6060
`,
6161
}, {

0 commit comments

Comments
 (0)