Skip to content

Commit

Permalink
feat(database): database 연동
Browse files Browse the repository at this point in the history
  • Loading branch information
mcauto committed Dec 3, 2021
1 parent a0922d7 commit f2732e2
Show file tree
Hide file tree
Showing 29 changed files with 970 additions and 76 deletions.
8 changes: 6 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
DATABASE_DSN="mysql://root:imdeo@tcp(127.0.0.1:3306)/todolist?charset=utf8mb4&parseTime=True&loc=Local"
PORT=5000
DATABASE_USER="deokim"
DATABASE_PASSWORD="imdeo"
DATABASE_NAME="todolist"
DATABASE_HOST=localhost
DATABASE_PORT=23306
PORT=5000
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# todolist-api

## architecture

![clean architecture](https://raw.githubusercontent.com/bxcodec/go-clean-arch/master/clean-arch.png)

## commands

- config: 실행 전 설정 값을 확인용
Expand Down
12 changes: 11 additions & 1 deletion deploy/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,20 @@ services:
- "23306:3306"
env_file:
- ./mysql/.env
volumes:
- type: bind
source: ./mysql/files
target: /var/lib/mysql-files
- type: bind
source: ./mysql/my.cnf
target: /etc/mysql/my.cnf
api:
image: ghcr.io/mcauto/todolist-api:latest
build:
context: ..
dockerfile: ./deploy/todolist-api/Dockerfile
env_file:
- ./todolist-api/.env
- ./todolist-api/.env
restart: always
depends_on:
- database
3 changes: 2 additions & 1 deletion deploy/mysql/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
MYSQL_USER=deokim
MYSQL_PASSWORD=imdeo
MYSQL_ROOT_PASSWORD=imdeo
MYSQL_DATABASE=todolist
MYSQL_HOST=localhost
MYSQL_DATABASE=todolist
Empty file added deploy/mysql/files/.gitkeep
Empty file.
8 changes: 6 additions & 2 deletions deploy/todolist-api/.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
DATABASE_DSN="mysql://root:imdeo@tcp(127.0.0.1:3306)/todolist?charset=utf8mb4&parseTime=True&loc=Local"
PORT=5000
DATABASE_USER="deokim"
DATABASE_PASSWORD="imdeo"
DATABASE_NAME="todolist"
DATABASE_HOST=database
DATABASE_PORT=3306
PORT=5000
4 changes: 3 additions & 1 deletion deploy/todolist-api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM golang:1.17.3-alpine as build

RUN sed -i 's/https/http/g' /etc/apk/repositories

RUN go install golang.org/x/lint/golint@latest \
&& go install github.com/securego/gosec/v2/cmd/gosec@latest \
&& go install github.com/axw/gocov/gocov@latest \
Expand All @@ -19,4 +21,4 @@ FROM scratch

COPY --from=build /go/src/todolist-api/bin/todolist-api /usr/bin/todolist-api

CMD ["todolist-api", "run"]
CMD ["todolist-api", "run"]
229 changes: 227 additions & 2 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,232 @@ var doc = `{
},
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {},
"paths": {
"/todos": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "todo get all",
"produces": [
"application/json"
],
"tags": [
"todo"
],
"summary": "todo get all",
"operationId": "todo-get-all",
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/todo.Item"
}
}
},
"204": {
"description": ""
},
"400": {
"description": "Bad Request",
"schema": {
"type": "object"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"type": "object"
}
}
}
},
"post": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "todo post",
"produces": [
"application/json"
],
"tags": [
"todo"
],
"summary": "todo post",
"operationId": "todo-post",
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object"
}
},
"204": {
"description": ""
},
"400": {
"description": "Bad Request",
"schema": {
"type": "object"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"type": "object"
}
}
}
},
"delete": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "todo delete",
"produces": [
"application/json"
],
"tags": [
"todo"
],
"summary": "todo delete",
"operationId": "todo-delete",
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object"
}
},
"204": {
"description": ""
},
"400": {
"description": "Bad Request",
"schema": {
"type": "object"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"type": "object"
}
}
}
},
"patch": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "todo patch",
"produces": [
"application/json"
],
"tags": [
"todo"
],
"summary": "todo patch",
"operationId": "todo-patch",
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object"
}
},
"204": {
"description": ""
},
"400": {
"description": "Bad Request",
"schema": {
"type": "object"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"type": "object"
}
}
}
}
},
"/todos/:id": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "todo get",
"produces": [
"application/json"
],
"tags": [
"todo"
],
"summary": "todo get",
"operationId": "todo-get",
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "object"
}
},
"204": {
"description": ""
},
"400": {
"description": "Bad Request",
"schema": {
"type": "object"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"type": "object"
}
}
}
}
}
},
"definitions": {
"todo.Item": {
"type": "object",
"properties": {
"checked": {
"type": "boolean"
},
"created": {
"type": "string"
},
"id": {
"type": "integer"
},
"title": {
"type": "string"
},
"updated": {
"type": "string"
}
}
}
},
"securityDefinitions": {
"ApiKeyAuth": {
"type": "apiKey",
Expand Down Expand Up @@ -87,5 +312,5 @@ func (s *s) ReadDoc() string {
}

func init() {
swag.Register("swagger", &s{})
swag.Register(swag.Name, &s{})
}
Loading

0 comments on commit f2732e2

Please sign in to comment.