I want to use hot reload in my golang app. I use air package.
But when I modify my main.go, the api response is not changed.
↓ my app folders.
my-app
|--- app
| |--- .air.toml
| |--- Dockerfile
| |--- go.mod
| |--- go.sum
| |--- main.go
|
|--- docker-compose.yml
↓ Dockerfile
FROM golang:1.16
ENV GOPATH /go
ENV GO111MODULE on
COPY go.mod /var/www/html/go.mod
COPY go.sum /var/www/html/go.sum
WORKDIR /var/www/html/
RUN go mod download
RUN go mod tidy && \
go install github.com/cosmtrek/air@v1.27.3
COPY . /var/www/html/
CMD ["air", "-c", ".air.toml"]
↓ docker-compose.yml
version: '3'
services:
app:
build: ./app
tty: true
volumes:
- ./app:/var/www/html
depends_on:
- mysql
ports:
- "3000:3000"
command: "air"
↓ main.go
package main
import (
"net/http"
"github.com/gin-gonic/gin"
)
func main() {
engine := gin.Default()
engine.GET("/", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"message": "hello world",
})
})
engine.Run(":3000")
}
I created .air.toml by air init command in my app container.
And when I do command docker-compose up --build, I get ↓.
What is wrong?