Docker test
This commit is contained in:
parent
eef066b179
commit
9128b4aa0c
10
Dockerfile
10
Dockerfile
@ -1,17 +1,9 @@
|
|||||||
FROM golang:1.16.5 as builder
|
FROM golang:1.16.5 as builder
|
||||||
|
|
||||||
WORKDIR /go-microservice/
|
WORKDIR /go-microservice/
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
RUN CGO_ENABLED=0 go build -o microservice /go-microservice/main.go
|
RUN CGO_ENABLED=0 go build -o microservice /go-microservice/main.go
|
||||||
|
|
||||||
FROM alpine:latest
|
FROM alpine:latest
|
||||||
|
|
||||||
WORKDIR /go-microservice
|
WORKDIR /go-microservice
|
||||||
|
|
||||||
COPY --from=builder /go-microservice/ /go-microservice/
|
COPY --from=builder /go-microservice/ /go-microservice/
|
||||||
|
|
||||||
EXPOSE 9090
|
EXPOSE 9090
|
||||||
|
CMD ./microservice
|
||||||
CMD ./microservice
|
|
||||||
|
@ -14,3 +14,10 @@ go run .\main.go
|
|||||||
```
|
```
|
||||||
|
|
||||||
Use the above command to run API on your local machine on port 9090.
|
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
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
// "os"
|
||||||
|
|
||||||
"github.com/HelloWorld/goProductAPI/entity"
|
"github.com/HelloWorld/goProductAPI/entity"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
@ -150,8 +150,10 @@ func AuthHandler(h http.Handler) http.HandlerFunc {
|
|||||||
return func(rw http.ResponseWriter, r *http.Request) {
|
return func(rw http.ResponseWriter, r *http.Request) {
|
||||||
user, pass, ok := r.BasicAuth()
|
user, pass, ok := r.BasicAuth()
|
||||||
if ok {
|
if ok {
|
||||||
username := sha256.Sum256([]byte(os.Getenv("USER_NAME")))
|
// username := sha256.Sum256([]byte(os.Getenv("USER_NAME")))
|
||||||
password := sha256.Sum256([]byte(os.Getenv("USER_PASS")))
|
// password := sha256.Sum256([]byte(os.Getenv("USER_PASS")))
|
||||||
|
username := sha256.Sum256([]byte("1234"))
|
||||||
|
password := sha256.Sum256([]byte("1234"))
|
||||||
userHash := sha256.Sum256([]byte(user))
|
userHash := sha256.Sum256([]byte(user))
|
||||||
passHash := sha256.Sum256([]byte(pass))
|
passHash := sha256.Sum256([]byte(pass))
|
||||||
validUser := subtle.ConstantTimeCompare(userHash[:],username[:]) == 1
|
validUser := subtle.ConstantTimeCompare(userHash[:],username[:]) == 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user