├── .github └── workflows │ └── lint.yml ├── .gitignore ├── LICENSE ├── README.md ├── docker-compose.yml ├── golang ├── .gitignore ├── Dockerfile ├── controllers │ └── todoController.go ├── go.mod ├── go.sum ├── models │ ├── todo.go │ └── todoDb.go └── server.go └── nuxt ├── .gitignore ├── Dockerfile ├── README.md ├── assets └── README.md ├── components ├── Logo.vue ├── README.md ├── TodoApp.vue ├── TodoCard.vue └── TodoForm.vue ├── jsconfig.json ├── layouts ├── README.md └── default.vue ├── middleware └── README.md ├── nuxt.config.js ├── package.json ├── pages ├── README.md └── index.vue ├── plugins └── README.md ├── static ├── README.md └── favicon.ico ├── store └── README.md ├── stylelint.config.js ├── tsconfig.json └── yarn.lock /.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | name: lint 2 | on: push 3 | jobs: 4 | build: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - uses: actions/checkout@v2 8 | - name: Install modules 9 | run: cd nuxt && yarn install 10 | - name: Run ESLint 11 | run: cd nuxt && yarn lint:style 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /mysql -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 nagaokayuji 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nuxt-golang-sample ![license](https://img.shields.io/github/license/nagaokayuji/nuxt-golang) ![size](https://img.shields.io/github/languages/code-size/nagaokayuji/nuxt-golang) ![forks](https://img.shields.io/github/forks/nagaokayuji/nuxt-golang) 2 | 3 | RESTful API server and SPA. 4 | 5 | ## About 6 | 7 | - [Docker](https://www.docker.com/) as the container service 8 | - [MySQL](https://www.mysql.com/) 5.7 as the database 9 | - [Golang](https://golang.org/) 1.16.0 as the RESTFul API server 10 | - [Node.js](https://nodejs.org/en/) 15.11.0 as the run-time environment to run JavaScript 11 | 12 | ## Running the app in local development 13 | 14 | - build 15 | 16 | ```sh 17 | $ docker-compose build 18 | ``` 19 | 20 | - run app 21 | 22 | Simply run: 23 | 24 | ```sh 25 | $ docker-compose run 26 | ``` 27 | 28 | By default you can access server via http://localhost:3000 29 | 30 | # Contributing 31 | 32 | Your contributions are always welcome! 33 | Feel free to raise Issues, or send Pull Requests. 34 | 35 | # License 36 | 37 | MIT License. 38 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3" 2 | services: 3 | app: 4 | container_name: app 5 | build: ./golang 6 | volumes: 7 | - ./golang:/golang 8 | ports: 9 | - "8080:8080" 10 | depends_on: 11 | db: 12 | condition: service_healthy 13 | command: sh -c "fresh" 14 | 15 | nuxt: 16 | container_name: nuxt 17 | build: ./nuxt 18 | ports: 19 | - 3000:3000 20 | volumes: 21 | - ./nuxt:/app 22 | - /app/node_modules 23 | stdin_open: true 24 | tty: true 25 | command: sh -c "yarn && yarn dev" 26 | 27 | db: 28 | container_name: db 29 | platform: linux/x86_64 # M1 Mac対応のため 30 | image: mysql:5.7 31 | volumes: 32 | - ./mysql/conf:/etc/mysql/conf.d 33 | - ./mysql/data:/var/lib/mysql 34 | command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci 35 | ports: 36 | - 3306:3306 37 | environment: 38 | MYSQL_DATABASE: golang-nuxt-app 39 | MYSQL_ROOT_PASSWORD: password 40 | MYSQL_USER: root 41 | TZ: "Asia/Tokyo" 42 | healthcheck: 43 | test: "/etc/init.d/mysql status" 44 | interval: 1s 45 | retries: 60 46 | -------------------------------------------------------------------------------- /golang/.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, built with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | 14 | # Dependency directories (remove the comment below to include it) 15 | # vendor/ 16 | 17 | tmp -------------------------------------------------------------------------------- /golang/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.16.0-alpine 2 | 3 | WORKDIR /golang 4 | ADD . /golang 5 | 6 | ENV GO111MODULE=on 7 | 8 | RUN apk add --no-cache \ 9 | alpine-sdk \ 10 | git \ 11 | && go get github.com/pilu/fresh \ 12 | && go get github.com/gin-gonic/gin \ 13 | && go get github.com/go-sql-driver/mysql \ 14 | && go get github.com/jinzhu/gorm 15 | 16 | 17 | EXPOSE 8080 18 | 19 | CMD ["fresh"] 20 | -------------------------------------------------------------------------------- /golang/controllers/todoController.go: -------------------------------------------------------------------------------- 1 | package controllers 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | 7 | "time" 8 | 9 | "golang/models" 10 | 11 | "github.com/gin-gonic/gin" 12 | "github.com/google/uuid" 13 | ) 14 | 15 | // 全件取得 16 | func GetAllTodos(c *gin.Context) { 17 | var todos []models.Todo 18 | models.DB.Order("created_at desc").Find(&todos) 19 | c.JSON(http.StatusOK, todos) 20 | } 21 | 22 | // UUIDから1件取得 23 | func GetTodo(c *gin.Context) { 24 | uuid := c.Params.ByName("uuid") 25 | var todo models.Todo 26 | if err := models.DB.Where("uuid = ?", uuid).First(&todo).Error; err != nil { 27 | c.AbortWithStatus(404) 28 | fmt.Println(err) 29 | return 30 | } 31 | 32 | c.JSON(http.StatusOK, todo) 33 | } 34 | 35 | // 1件登録 36 | func CreateTodo(c *gin.Context) { 37 | var input models.CreateTodoInput 38 | 39 | if err := c.ShouldBindJSON(&input); err != nil { 40 | c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) 41 | fmt.Println(err.Error()) 42 | return 43 | } 44 | 45 | todo := models.Todo{UUID: uuid.New().String(), Title: input.Title, State: false, Deadline: input.Deadline, CreatedAt: time.Now(), UpdatedAt: time.Now()} 46 | models.DB.Create(&todo) 47 | c.JSON(http.StatusOK, todo) 48 | } 49 | 50 | func ToggleStatus(c *gin.Context) { 51 | uuid := c.Params.ByName("uuid") 52 | var todo models.Todo 53 | if err := models.DB.Where("uuid = ?", uuid).First(&todo).Error; err != nil { 54 | c.AbortWithStatus(404) 55 | fmt.Println(err) 56 | return 57 | } 58 | todo.State = !todo.State 59 | models.DB.Save(&todo) 60 | c.JSON(http.StatusOK, todo) 61 | } 62 | 63 | func DeleteTodo(c *gin.Context) { 64 | uuid := c.Params.ByName("uuid") 65 | if row := models.DB.Delete(&models.Todo{}, "uuid = ?", uuid).RowsAffected; row != 1 { 66 | c.AbortWithStatus(404) 67 | return 68 | } 69 | c.Status(http.StatusOK) 70 | } 71 | -------------------------------------------------------------------------------- /golang/go.mod: -------------------------------------------------------------------------------- 1 | module golang 2 | 3 | go 1.16 4 | 5 | require ( 6 | github.com/gin-gonic/gin v1.6.3 // indirect 7 | github.com/go-sql-driver/mysql v1.5.0 // indirect 8 | github.com/google/uuid v1.2.0 // indirect 9 | github.com/jinzhu/gorm v1.9.16 // indirect 10 | github.com/mattn/go-sqlite3 v2.0.1+incompatible // indirect 11 | ) 12 | -------------------------------------------------------------------------------- /golang/go.sum: -------------------------------------------------------------------------------- 1 | github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc= 2 | github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y= 3 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 4 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 5 | github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU= 6 | github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0= 7 | github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= 8 | github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= 9 | github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14= 10 | github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= 11 | github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= 12 | github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= 13 | github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= 14 | github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= 15 | github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= 16 | github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1Vv0sFl1UcHBOY= 17 | github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= 18 | github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs= 19 | github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= 20 | github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= 21 | github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I= 22 | github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= 23 | github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= 24 | github.com/google/uuid v1.2.0 h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs= 25 | github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 26 | github.com/howeyc/fsnotify v0.9.0/go.mod h1:41HzSPxBGeFRQKEEwgh49TRw/nKBsYZ2cF1OzPjSJsA= 27 | github.com/jinzhu/gorm v1.9.16 h1:+IyIjPEABKRpsu/F8OvDPy9fyQlgsg2luMV2ZIH5i5o= 28 | github.com/jinzhu/gorm v1.9.16/go.mod h1:G3LB3wezTOWM2ITLzPxEXgSkOXAntiLHS7UdBefADcs= 29 | github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= 30 | github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= 31 | github.com/jinzhu/now v1.0.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= 32 | github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns= 33 | github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= 34 | github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= 35 | github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= 36 | github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= 37 | github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= 38 | github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= 39 | github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= 40 | github.com/mattn/go-sqlite3 v1.14.0/go.mod h1:JIl7NbARA7phWnGvh0LKTyg7S9BA+6gx71ShQilpsus= 41 | github.com/mattn/go-sqlite3 v2.0.1+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= 42 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= 43 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 44 | github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg= 45 | github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 46 | github.com/pilu/config v0.0.0-20131214182432-3eb99e6c0b9a/go.mod h1:9Or9aIl95Kp43zONcHd5tLZGKXb9iLx0pZjau0uJ5zg= 47 | github.com/pilu/fresh v0.0.0-20190826141211-0fa698148017/go.mod h1:2LLTtftTZSdAPR/iVyennXZDLZOYzyDn+T0qEKJ8eSw= 48 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 49 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 50 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 51 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 52 | github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= 53 | github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= 54 | github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs= 55 | github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= 56 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 57 | golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 58 | golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 59 | golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 60 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 61 | golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 62 | golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= 63 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 64 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 65 | golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg= 66 | golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 67 | golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 68 | golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884= 69 | golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 70 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 71 | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= 72 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 73 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 74 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 75 | gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= 76 | gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 77 | -------------------------------------------------------------------------------- /golang/models/todo.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import "time" 4 | 5 | type Todo struct { 6 | UUID string `gorm:"type:varchar(36); primary_key; not null" json:"uuid"` 7 | Title string `gorm:"type:varchar(200);not null" json:"title"` 8 | State bool `gorm:"not null" json:"state"` 9 | Deadline time.Time `gorm:"not null" json:"deadline"` 10 | CreatedAt time.Time `gorm:"not null" json:"created_at" sql:"DEFAULT:CURRENT_TIMESTAMP"` 11 | UpdatedAt time.Time `gorm:"not null" json:"updated_at" sql:"DEFAULT:CURRENT_TIMESTAMP"` 12 | } 13 | 14 | type CreateTodoInput struct { 15 | Title string `json:"title"` 16 | Deadline time.Time `json:"deadline"` 17 | } 18 | -------------------------------------------------------------------------------- /golang/models/todoDb.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import ( 4 | "fmt" 5 | 6 | _ "github.com/go-sql-driver/mysql" 7 | "github.com/jinzhu/gorm" 8 | ) 9 | 10 | var DB *gorm.DB 11 | 12 | func SetupDB() { 13 | DBMS := "mysql" 14 | USER := "root" 15 | PASS := "password" 16 | HOST := "db" 17 | PORT := "3306" 18 | DBNAME := "golang-nuxt-app" 19 | 20 | URL := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=True&loc=Local", USER, PASS, HOST, PORT, DBNAME) 21 | 22 | fmt.Println("connecting URL = ", URL) 23 | 24 | db, err := gorm.Open(DBMS, URL) 25 | 26 | if err != nil { 27 | panic(err.Error()) 28 | } 29 | 30 | db.Set("gorm:table_options", "ENGINE=InnoDB") 31 | 32 | fmt.Println("db connected: ", &db) 33 | DB = db 34 | } 35 | -------------------------------------------------------------------------------- /golang/server.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "golang/controllers" 5 | "golang/models" 6 | 7 | "github.com/gin-gonic/gin" 8 | _ "github.com/jinzhu/gorm/dialects/mysql" 9 | ) 10 | 11 | func main() { 12 | // 起動 13 | server() 14 | } 15 | 16 | func server() { 17 | models.SetupDB() 18 | models.DB.AutoMigrate(&models.Todo{}) 19 | 20 | r := gin.Default() 21 | 22 | r.Use(func(c *gin.Context) { 23 | c.Set("db", models.DB) 24 | }) 25 | 26 | r.GET("/", func(c *gin.Context) { 27 | c.JSON(200, gin.H{ 28 | "message": "hello world from api", 29 | }) 30 | }) 31 | 32 | // 全件 33 | r.GET("/todos", controllers.GetAllTodos) 34 | // 1件 35 | r.GET("/todos/:uuid", controllers.GetTodo) 36 | // 1件作成 37 | r.POST("/todos", controllers.CreateTodo) 38 | // toggle 39 | r.PATCH("/todos/:uuid", controllers.ToggleStatus) 40 | // delete 41 | r.DELETE("/todos/:uuid", controllers.DeleteTodo) 42 | 43 | r.Run(":8080") 44 | } 45 | -------------------------------------------------------------------------------- /nuxt/.gitignore: -------------------------------------------------------------------------------- 1 | logs 2 | *.log 3 | npm-debug.log* 4 | yarn-debug.log* 5 | yarn-error.log* 6 | lerna-debug.log* 7 | 8 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 9 | 10 | pids 11 | *.pid 12 | *.seed 13 | *.pid.lock 14 | lib-cov 15 | 16 | coverage 17 | *.lcov 18 | .nyc_output 19 | .grunt 20 | 21 | bower_components 22 | 23 | .lock-wscript 24 | 25 | build/Release 26 | 27 | node_modules/ 28 | jspm_packages/ 29 | package-lock.json 30 | 31 | typings/ 32 | 33 | *.tsbuildinfo 34 | 35 | .npm 36 | 37 | .eslintcache 38 | 39 | .stylelintcache 40 | 41 | # Microbundle cache 42 | .rpt2_cache/ 43 | .rts2_cache_cjs/ 44 | .rts2_cache_es/ 45 | .rts2_cache_umd/ 46 | 47 | # Optional REPL history 48 | .node_repl_history 49 | 50 | # Output of 'npm pack' 51 | *.tgz 52 | 53 | # Yarn Integrity file 54 | .yarn-integrity 55 | 56 | # dotenv environment variables file 57 | .env 58 | .env.test 59 | .env*.local 60 | 61 | # parcel-bundler cache (https://parceljs.org/) 62 | .cache 63 | .parcel-cache 64 | 65 | .next 66 | 67 | .nuxt 68 | dist 69 | 70 | .cache/ 71 | # vuepress build output 72 | .vuepress/dist 73 | 74 | # Serverless directories 75 | .serverless/ 76 | 77 | # FuseBox cache 78 | .fusebox/ 79 | 80 | # DynamoDB Local files 81 | .dynamodb/ 82 | 83 | # TernJS port file 84 | .tern-port 85 | 86 | # Stores VSCode versions used for testing VSCode extensions 87 | .vscode-test 88 | 89 | ### Go ### 90 | # Binaries for programs and plugins 91 | *.exe 92 | *.exe~ 93 | *.dll 94 | *.so 95 | *.dylib 96 | 97 | # Test binary, built with `go test -c` 98 | *.test 99 | 100 | # Output of the go coverage tool, specifically when used with LiteIDE 101 | *.out 102 | 103 | # Dependency directories (remove the comment below to include it) 104 | # vendor/ 105 | 106 | ### Go Patch ### 107 | /vendor/ 108 | /Godeps/ 109 | 110 | # End of https://www.toptal.com/developers/gitignore/api/go -------------------------------------------------------------------------------- /nuxt/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:15.11.0-alpine 2 | 3 | ENV HOST 0.0.0.0 4 | EXPOSE 3000 5 | 6 | WORKDIR /app 7 | COPY ./package.json /app 8 | COPY ./package-lock.json /app 9 | COPY . /app 10 | 11 | RUN npm install 12 | 13 | 14 | # RUN yarn 15 | 16 | CMD ["yarn", "dev"] -------------------------------------------------------------------------------- /nuxt/README.md: -------------------------------------------------------------------------------- 1 | # nuxt 2 | 3 | ## Build Setup 4 | 5 | ```bash 6 | # install dependencies 7 | $ yarn install 8 | 9 | # serve with hot reload at localhost:3000 10 | $ yarn dev 11 | 12 | # build for production and launch server 13 | $ yarn build 14 | $ yarn start 15 | 16 | # generate static project 17 | $ yarn generate 18 | ``` 19 | 20 | For detailed explanation on how things work, check out [Nuxt.js docs](https://nuxtjs.org). 21 | -------------------------------------------------------------------------------- /nuxt/assets/README.md: -------------------------------------------------------------------------------- 1 | # ASSETS 2 | 3 | **This directory is not required, you can delete it if you don't want to use it.** 4 | 5 | This directory contains your un-compiled assets such as LESS, SASS, or JavaScript. 6 | 7 | More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/assets#webpacked). 8 | -------------------------------------------------------------------------------- /nuxt/components/Logo.vue: -------------------------------------------------------------------------------- 1 | 23 | 24 | 36 | -------------------------------------------------------------------------------- /nuxt/components/README.md: -------------------------------------------------------------------------------- 1 | # COMPONENTS 2 | 3 | **This directory is not required, you can delete it if you don't want to use it.** 4 | 5 | The components directory contains your Vue.js Components. 6 | 7 | _Nuxt.js doesn't supercharge these components._ 8 | -------------------------------------------------------------------------------- /nuxt/components/TodoApp.vue: -------------------------------------------------------------------------------- 1 | 10 | 11 | 59 | 65 | -------------------------------------------------------------------------------- /nuxt/components/TodoCard.vue: -------------------------------------------------------------------------------- 1 | 10 | 11 | 44 | 140 | -------------------------------------------------------------------------------- /nuxt/components/TodoForm.vue: -------------------------------------------------------------------------------- 1 | 10 | 11 | 44 | 90 | -------------------------------------------------------------------------------- /nuxt/jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": ".", 4 | "paths": { 5 | "~/*": ["./*"], 6 | "@/*": ["./*"], 7 | "~~/*": ["./*"], 8 | "@@/*": ["./*"] 9 | } 10 | }, 11 | "exclude": ["node_modules", ".nuxt", "dist"] 12 | } 13 | -------------------------------------------------------------------------------- /nuxt/layouts/README.md: -------------------------------------------------------------------------------- 1 | # LAYOUTS 2 | 3 | **This directory is not required, you can delete it if you don't want to use it.** 4 | 5 | This directory contains your Application Layouts. 6 | 7 | More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/views#layouts). 8 | -------------------------------------------------------------------------------- /nuxt/layouts/default.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 18 | -------------------------------------------------------------------------------- /nuxt/middleware/README.md: -------------------------------------------------------------------------------- 1 | # MIDDLEWARE 2 | 3 | **This directory is not required, you can delete it if you don't want to use it.** 4 | 5 | This directory contains your application middleware. 6 | Middleware let you define custom functions that can be run before rendering either a page or a group of pages. 7 | 8 | More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/routing#middleware). 9 | -------------------------------------------------------------------------------- /nuxt/nuxt.config.js: -------------------------------------------------------------------------------- 1 | export default { 2 | // Disable server-side rendering: https://go.nuxtjs.dev/ssr-mode 3 | ssr: false, 4 | server: { 5 | port: 3000, 6 | host: '0.0.0.0', 7 | }, 8 | axios: { 9 | proxy: true 10 | }, 11 | proxy: { 12 | '/api/': { 13 | target: 'http://app:8080', // dockerのやつ 14 | pathRewrite: {'^/api/': '/'}, 15 | } 16 | }, 17 | // Global page headers: https://go.nuxtjs.dev/config-head 18 | head: { 19 | title: 'nuxt', 20 | htmlAttrs: { 21 | lang: 'en', 22 | }, 23 | meta: [ 24 | { charset: 'utf-8' }, 25 | { name: 'viewport', content: 'width=device-width, initial-scale=1' }, 26 | { hid: 'description', name: 'description', content: '' }, 27 | ], 28 | link: [{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }], 29 | }, 30 | 31 | // Global CSS: https://go.nuxtjs.dev/config-css 32 | css: [], 33 | 34 | // Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins 35 | plugins: [], 36 | 37 | // Auto import components: https://go.nuxtjs.dev/config-components 38 | components: true, 39 | 40 | // Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules 41 | buildModules: [ 42 | // https://go.nuxtjs.dev/typescript 43 | '@nuxt/typescript-build', 44 | // https://go.nuxtjs.dev/stylelint 45 | '@nuxtjs/stylelint-module', 46 | ], 47 | 48 | // Modules: https://go.nuxtjs.dev/config-modules 49 | modules: [ 50 | // https://go.nuxtjs.dev/axios 51 | '@nuxtjs/axios', 52 | '@nuxtjs/proxy', 53 | 54 | ], 55 | 56 | // Axios module configuration: https://go.nuxtjs.dev/config-axios 57 | axios: {}, 58 | 59 | // Build Configuration: https://go.nuxtjs.dev/config-build 60 | build: {}, 61 | } 62 | -------------------------------------------------------------------------------- /nuxt/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nuxt", 3 | "version": "1.0.0", 4 | "private": true, 5 | "scripts": { 6 | "dev": "nuxt-ts", 7 | "build": "nuxt-ts build", 8 | "start": "nuxt-ts start", 9 | "generate": "nuxt-ts generate", 10 | "lint:js": "eslint --ext \".js,.vue\" --ignore-path .gitignore .", 11 | "lint:style": "stylelint \"**/*.{vue,css}\" --ignore-path .gitignore", 12 | "lint": "yarn lint:js && yarn lint:style" 13 | }, 14 | "dependencies": { 15 | "@nuxt/typescript-runtime": "^2.0.1", 16 | "@nuxtjs/axios": "^5.13.1", 17 | "core-js": "^3.8.3", 18 | "moment": "^2.29.1", 19 | "nuxt": "^2.14.12" 20 | }, 21 | "devDependencies": { 22 | "@nuxt/types": "^2.14.12", 23 | "@nuxt/typescript-build": "^2.0.4", 24 | "@nuxtjs/eslint-config-typescript": "^5.0.0", 25 | "@nuxtjs/eslint-module": "^3.0.2", 26 | "@nuxtjs/stylelint-module": "^4.0.0", 27 | "babel-eslint": "^10.1.0", 28 | "eslint": "^7.18.0", 29 | "eslint-config-prettier": "^7.2.0", 30 | "eslint-plugin-nuxt": "^2.0.0", 31 | "eslint-plugin-prettier": "^3.3.1", 32 | "eslint-plugin-vue": "^7.5.0", 33 | "prettier": "^2.2.1", 34 | "pug": "^3.0.2", 35 | "pug-plain-loader": "^1.1.0", 36 | "sass": "^1.32.8", 37 | "stylelint": "^13.9.0", 38 | "stylelint-config-prettier": "^8.0.2", 39 | "stylelint-config-standard": "^20.0.0" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /nuxt/pages/README.md: -------------------------------------------------------------------------------- 1 | # PAGES 2 | 3 | This directory contains your Application Views and Routes. 4 | The framework reads all the `*.vue` files inside this directory and creates the router of your application. 5 | 6 | More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/routing). 7 | -------------------------------------------------------------------------------- /nuxt/pages/index.vue: -------------------------------------------------------------------------------- 1 | 5 | 6 | 11 | 12 | 20 | -------------------------------------------------------------------------------- /nuxt/plugins/README.md: -------------------------------------------------------------------------------- 1 | # PLUGINS 2 | 3 | **This directory is not required, you can delete it if you don't want to use it.** 4 | 5 | This directory contains Javascript plugins that you want to run before mounting the root Vue.js application. 6 | 7 | More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/plugins). 8 | -------------------------------------------------------------------------------- /nuxt/static/README.md: -------------------------------------------------------------------------------- 1 | # STATIC 2 | 3 | **This directory is not required, you can delete it if you don't want to use it.** 4 | 5 | This directory contains your static files. 6 | Each file inside this directory is mapped to `/`. 7 | Thus you'd want to delete this README.md before deploying to production. 8 | 9 | Example: `/static/robots.txt` is mapped as `/robots.txt`. 10 | 11 | More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/assets#static). 12 | -------------------------------------------------------------------------------- /nuxt/static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phpblackbox/Nuxtjs-golang/c3094eb8fc504b2b8a56d9b3f5d1e4edda032072/nuxt/static/favicon.ico -------------------------------------------------------------------------------- /nuxt/store/README.md: -------------------------------------------------------------------------------- 1 | # STORE 2 | 3 | **This directory is not required, you can delete it if you don't want to use it.** 4 | 5 | This directory contains your Vuex Store files. 6 | Vuex Store option is implemented in the Nuxt.js framework. 7 | 8 | Creating a file in this directory automatically activates the option in the framework. 9 | 10 | More information about the usage of this directory in [the documentation](https://nuxtjs.org/guide/vuex-store). 11 | -------------------------------------------------------------------------------- /nuxt/stylelint.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ['stylelint-config-standard', 'stylelint-config-prettier'], 3 | // add your custom config here 4 | // https://stylelint.io/user-guide/configuration 5 | rules: {}, 6 | } 7 | -------------------------------------------------------------------------------- /nuxt/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2018", 4 | "module": "ESNext", 5 | "moduleResolution": "Node", 6 | "lib": [ 7 | "ESNext", 8 | "ESNext.AsyncIterable", 9 | "DOM" 10 | ], 11 | "esModuleInterop": true, 12 | "allowJs": true, 13 | "sourceMap": true, 14 | "strict": true, 15 | "noEmit": true, 16 | "experimentalDecorators": true, 17 | "baseUrl": ".", 18 | "paths": { 19 | "~/*": [ 20 | "./*" 21 | ], 22 | "@/*": [ 23 | "./*" 24 | ] 25 | }, 26 | "types": [ 27 | "@nuxt/types", 28 | "@nuxtjs/axios", 29 | "@types/node" 30 | ] 31 | }, 32 | "exclude": [ 33 | "node_modules", 34 | ".nuxt", 35 | "dist" 36 | ] 37 | } 38 | --------------------------------------------------------------------------------