diff --git a/Dockerfile b/Dockerfile index c9ee3d0..efb47af 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,9 @@ FROM golang:1.16.5 as builder - WORKDIR /go-microservice/ - COPY . . - RUN CGO_ENABLED=0 go build -o microservice /go-microservice/main.go - FROM alpine:latest - WORKDIR /go-microservice - COPY --from=builder /go-microservice/ /go-microservice/ - EXPOSE 9090 - -CMD ./microservice \ No newline at end of file +CMD ./microservice diff --git a/README.md b/README.md index 1d51710..3fb1e5f 100644 --- a/README.md +++ b/README.md @@ -14,3 +14,10 @@ go run .\main.go ``` Use the above command to run API on your local machine on port 9090. + + +Building Docker Image +> docker build -t microsrvice . +> docker images +> docker run -p 9090:9090 microservice + diff --git a/handlers/handlers.go b/handlers/handlers.go index 993c5c6..2a66f20 100644 --- a/handlers/handlers.go +++ b/handlers/handlers.go @@ -7,7 +7,7 @@ import ( "errors" "io/ioutil" "net/http" - "os" +// "os" "github.com/HelloWorld/goProductAPI/entity" "github.com/gorilla/mux" @@ -150,8 +150,10 @@ func AuthHandler(h http.Handler) http.HandlerFunc { return func(rw http.ResponseWriter, r *http.Request) { user, pass, ok := r.BasicAuth() if ok { - username := sha256.Sum256([]byte(os.Getenv("USER_NAME"))) - password := sha256.Sum256([]byte(os.Getenv("USER_PASS"))) +// username := sha256.Sum256([]byte(os.Getenv("USER_NAME"))) +// password := sha256.Sum256([]byte(os.Getenv("USER_PASS"))) +username := sha256.Sum256([]byte("1234")) +password := sha256.Sum256([]byte("1234")) userHash := sha256.Sum256([]byte(user)) passHash := sha256.Sum256([]byte(pass)) validUser := subtle.ConstantTimeCompare(userHash[:],username[:]) == 1