5
0
Fork 0

Initial commit

master
Daniel Lim 2019-06-20 08:30:36 +08:00
parent c8772790b2
commit 8b2e437ecb
5 changed files with 57 additions and 0 deletions

1
.env Normal file
View File

@ -0,0 +1 @@
LISTEN=:80

15
Dockerfile Normal file
View File

@ -0,0 +1,15 @@
FROM golang:1.11-rc-alpine as build
RUN apk add --no-cache git=2.18.1-r0
WORKDIR /src
COPY go.mod go.sum .env *.go ./
RUN go get -d -v ./...
RUN CGO_ENABLED=0 go build -ldflags "-s -w"
FROM scratch
COPY --from=build /src/pictures /pictures
COPY --from=build /src/.env /.env
ENTRYPOINT ["/pictures"]

8
go.mod Normal file
View File

@ -0,0 +1,8 @@
module pictures
go 1.12
require (
github.com/joho/godotenv v1.3.0
github.com/julienschmidt/httprouter v1.2.0
)

4
go.sum Normal file
View File

@ -0,0 +1,4 @@
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/julienschmidt/httprouter v1.2.0 h1:TDTW5Yz1mjftljbcKqRcrYhd4XeOoI98t+9HbQbYf7g=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=

29
main.go Normal file
View File

@ -0,0 +1,29 @@
package main
import (
"encoding/json"
"log"
"net/http"
"os"
"github.com/joho/godotenv"
"github.com/julienschmidt/httprouter"
)
var listen string
func main() {
// Load .env
err := godotenv.Load()
if err != nil {
log.Fatal("Error loading .env file")
}
listen = os.Getenv("LISTEN")
// Routes
router := httprouter.New()
// Start server
log.Printf("starting server on %s", listen)
log.Fatal(http.ListenAndServe(listen, router))
}