diff --git a/Makefile b/Makefile index e5f0ed7..959d2bb 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,15 @@ +# test: +# go test -v -cover -covermode=atmic ./... + +docker-build: + docker build -t go-test-server . + +docker-run: docker-build + docker-compose up --build -d + +docker-stop: + docker-compose down + replace-local-modules: go mod edit -replace github.com/grimoh/go-test-server/article/delivery/http=./article/delivery/http go mod edit -replace github.com/grimoh/go-test-server/article/delivery/http/middleware=./article/delivery/http/middleware diff --git a/app/main.go b/app/main.go index ba864cf..5811136 100644 --- a/app/main.go +++ b/app/main.go @@ -7,6 +7,7 @@ import ( "net/url" "time" + _ "github.com/go-sql-driver/mysql" "github.com/labstack/echo" "github.com/spf13/viper" @@ -38,7 +39,7 @@ func main() { val := url.Values{} val.Add("parseTime", "1") - val.Add("loc", "Asia/Japan") + val.Add("loc", "Local") dsn := fmt.Sprintf("%s?%s", conn, val.Encode()) diff --git a/config.json b/config.json new file mode 100644 index 0000000..5800983 --- /dev/null +++ b/config.json @@ -0,0 +1,17 @@ +{ + "debug": true, + "server": { + "address": ":9090" + }, + "context":{ + "timeout":2 + }, + "database": { + "host": "mysql", + "port": "3306", + "user": "user", + "pass": "password", + "name": "article" + } + +} diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..724a1bd --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,45 @@ +version: "3.8" +services: + web: + build: + context: . + dockerfile: Dockerfile + container_name: go-test-server + ports: + - 9090:9090 + depends_on: + mysql: + condition: service_healthy + volumes: + - ./config.json:/app/config.json + + adminer: + container_name: go-test-adminer + hostname: adminer + image: adminer:4.8.1 + restart: always + ports: + - 8080:8080 + environment: + ADMINER_DEFAULT_SERVER: go-test-mysql + ADMINER_DESIGN: dracula + depends_on: + mysql: + condition: service_healthy + + mysql: + image: mysql:5.7 + platform: linux/x86_64 + container_name: go-test-mysql + command: mysqld --user=root + ports: + - 3306:3306 + environment: + MYSQL_DATABASE: article + MYSQL_USER: user + MYSQL_PASSWORD: password + MYSQL_ROOT_PASSWORD: root + healthcheck: + test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"] + timeout: 5s + retries: 10 diff --git a/go.mod b/go.mod index ad13295..122db80 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.18 require ( github.com/gin-gonic/gin v1.8.1 + github.com/go-sql-driver/mysql v1.6.0 golang.org/x/sync v0.1.0 google.golang.org/protobuf v1.28.1 gopkg.in/go-playground/validator.v9 v9.31.0 diff --git a/go.sum b/go.sum index 17b23b2..afd584f 100644 --- a/go.sum +++ b/go.sum @@ -75,6 +75,8 @@ github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/j github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA= github.com/go-playground/validator/v10 v10.10.0 h1:I7mrTYv78z8k8VXa/qJlOlEXn/nBh+BF8dHX5nt/dr0= github.com/go-playground/validator/v10 v10.10.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXSGrTK4nAUsbPlLADvpJkos= +github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= +github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/goccy/go-json v0.9.7 h1:IcB+Aqpx/iMHu5Yooh7jEzJk1JZ7Pjtmys2ukPr7EeM= github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=