雑にgoする

1
2
3
4
5
6
7
8
9
10
11
FROM golang:alpine

RUN apk update && \
apk upgrade && \
apk add --no-cache \
bash \
git

WORKDIR /go/src/app
RUN go get github.com/pilu/fresh
CMD ["fresh"]
1
2
3
4
5
6
7
8
version: '3'
services:
app:
build: .
volumes:
- ./:/go/src/app
ports:
- '3000:3000'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package main

import (
"fmt"
"net/http"
"os"
)

type helloHandler struct{}

func (h *helloHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hello World")
}

func main() {
var port = os.Getenv("PORT")
if port == "" {
port = "3000"
}

handler := helloHandler{}
server := http.Server{
Addr: ":" + port,
Handler: &handler,
}

if os.Getenv("APP_ENV") == "production" {
server.ListenAndServe()
} else {
server.ListenAndServeTLS("./ssl/lvh.me.crt", "./ssl/lvh.me.key")
}
}
1
2
3
4
5
6
docker build . -t go-playground
docker run -it --rm -p 3000:3000 -v $PWD:/go/src/app go-playground

or

docker-compose up