docker build -t simple_api .
docker run -p 5000:5000 simple_api
$ curl 127.0.0.1:5000/World
Hello World!
$ curl 127.0.0.1:5000/hi
Hi
docker build -t simple_api .
docker run -p 5000:5000 simple_api
$ curl 127.0.0.1:5000/World
Hello World!
$ curl 127.0.0.1:5000/hi
Hi
FROM golang:latest | |
RUN mkdir /app | |
ADD . /app/ | |
WORKDIR /app | |
RUN go build -o main . | |
CMD ["/app/main"] |
package main | |
import ( | |
"fmt" | |
"log" | |
"net/http" | |
) | |
func main() { | |
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | |
fmt.Fprintf(w, "Hello %s!", r.URL.Path[1:]) | |
fmt.Println("RESTfulServ. on:5000, Controller:",r.URL.Path[1:]) | |
}) | |
http.HandleFunc("/hi", func(w http.ResponseWriter, r *http.Request){ | |
fmt.Fprintf(w, "Hi") | |
}) | |
log.Fatal(http.ListenAndServe(":5000", nil)) | |
} |