1
0
Fork 0

Add ca-certs

master
Ambrose Chua 2018-09-17 09:52:23 +08:00
parent 233a0b0631
commit 4911e597db
2 changed files with 9 additions and 10 deletions

View File

@ -4,6 +4,7 @@ ARG repo="github.com/productionwentdown/${name}"
FROM golang:1.10-alpine as go
RUN apk add --no-cache ca-certificates
ARG name
ARG repo
@ -15,12 +16,13 @@ ENV GOARCH=amd64
RUN go build -ldflags '-extldflags "-static"' -o ${name}
FROM alpine:3.7
FROM scratch
ARG name
ARG repo
EXPOSE 8080
COPY --from=go /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=go /go/src/${repo}/${name} /${name}
ENTRYPOINT ["/email-collector"]

View File

@ -40,22 +40,19 @@ func main() {
err := r.ParseForm()
if err != nil {
log.Println(err)
w.WriteHeader(400)
w.Write([]byte("An error occurred. Please try again"))
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
return
}
email := r.Form.Get("email")
if err := checkmail.ValidateFormat(email); err != nil {
log.Println(email, err)
w.WriteHeader(400)
w.Write([]byte("Email is not valid"))
http.Error(w, "Email is not valid", http.StatusBadRequest)
return
}
err = checkmail.ValidateHost(email)
if _, ok := err.(checkmail.SmtpError); !ok && err != nil {
log.Println(email, err)
w.WriteHeader(400)
w.Write([]byte("Email is not valid"))
http.Error(w, "Email is not valid", http.StatusBadRequest)
return
}
log.Println(email, "success")
@ -70,20 +67,20 @@ func main() {
payload, err := json.Marshal(object)
if err != nil {
log.Println("json.Marshal failed, not supposed to happen!")
w.WriteHeader(500)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
resp, err := http.Post(slack, "application/json", bytes.NewBuffer(payload))
if err != nil {
log.Println(err)
w.WriteHeader(500)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
body, _ := ioutil.ReadAll(resp.Body)
log.Println(body)
w.WriteHeader(500)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
}