diff options
-rw-r--r-- | Dockerfile | 2 | ||||
-rw-r--r-- | cmd/web/handlers.go | 18 | ||||
-rw-r--r-- | cmd/web/main.go | 17 | ||||
-rw-r--r-- | cmd/web/routes.go | 10 | ||||
-rw-r--r-- | main.go | 18 |
5 files changed, 46 insertions, 19 deletions
@@ -3,6 +3,6 @@ WORKDIR /app COPY go.mod ./ RUN go mod download && go mod verify COPY . . -RUN go build -v -o /usr/local/bin/app . +RUN go build -v -o /usr/local/bin/app ./cmd/web CMD ["app"] EXPOSE 4000 diff --git a/cmd/web/handlers.go b/cmd/web/handlers.go new file mode 100644 index 0000000..aed4103 --- /dev/null +++ b/cmd/web/handlers.go @@ -0,0 +1,18 @@ +package main + +import ( + "net/http" +) + +func (app *application) notFound(w http.ResponseWriter) { + http.Error(w, http.StatusText(401), 401) +} + +func (app *application) home(w http.ResponseWriter, r *http.Request) { + if r.URL.Path != "/" { + app.notFound(w) + return + } + + w.Write([]byte("Hello from DED")) +} diff --git a/cmd/web/main.go b/cmd/web/main.go new file mode 100644 index 0000000..bd7e500 --- /dev/null +++ b/cmd/web/main.go @@ -0,0 +1,17 @@ +package main + +import ( + "log" + "net/http" +) + +type application struct{} + +func main() { + app := &application{} + // mux := http.NewServeMux() + // mux.HandleFunc("/", home) + log.Print("starting server on :4000") + err := http.ListenAndServe(":4000", app.routes()) + log.Fatal(err) +} diff --git a/cmd/web/routes.go b/cmd/web/routes.go new file mode 100644 index 0000000..2761d99 --- /dev/null +++ b/cmd/web/routes.go @@ -0,0 +1,10 @@ +package main + +import "net/http" + +func (app *application) routes() *http.ServeMux { + mux := http.NewServeMux() + + mux.HandleFunc("/", app.home) + return mux +} diff --git a/main.go b/main.go deleted file mode 100644 index ce89e18..0000000 --- a/main.go +++ /dev/null @@ -1,18 +0,0 @@ -package main - -import ( - "log" - "net/http" -) - -func home(w http.ResponseWriter, r *http.Request) { - w.Write([]byte("Hello from DED")) -} - -func main() { - mux := http.NewServeMux() - mux.HandleFunc("/", home) - log.Print("starting server on :4000") - err := http.ListenAndServe(":4000", mux) - log.Fatal(err) -} |