DEV Community

Moataz Burhan
Moataz Burhan

Posted on

100DaysOfCode — Day 02

Alt Text

In day 2, I started creating a simple service and Dockerfile. See the code here https://github.com/MoatazBurhan/Grunderound. To test this code, install Docker first. Follow this document to instructions: https://docs.docker.com/get-started/.
Go Code

This code simply reads your URL path and display it in the browser.

package main

import (
   "fmt"
   "html"
   "log"
   "net/http"
)

func main() {

   http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
      fmt.Fprintf(w, "redirecting to link based on %q", html.EscapeString(r.URL.Path))
   })

   log.Fatal(http.ListenAndServe(":8081", nil))
}
Enter fullscreen mode Exit fullscreen mode

Dockerfile

FROM golang:1.15.8
RUN mkdir /app
ADD . /app
WORKDIR /app
RUN go build -o main .
CMD ["/app/main"]
Enter fullscreen mode Exit fullscreen mode

Deploying the Application

$ git clone https://github.com/MoatazBurhan/Grunderound
$ docker build -t go-service .
$ docker run -d -p 8080:8081 go-service
Enter fullscreen mode Exit fullscreen mode

If you open up http://localhost:8080 within your browser, you should see that the application is successfully responding with redirecting to link based on "/".

End of day 2 of 100DaysOfCode.

Top comments (0)