Docker test

This commit is contained in:
José David Guillén 2021-09-15 19:11:17 +00:00
parent eef066b179
commit 9128b4aa0c
3 changed files with 13 additions and 12 deletions

View File

@ -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
CMD ./microservice

View File

@ -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

View File

@ -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