diff --git a/Containerfile b/Containerfile index ee89379..98363f4 100644 --- a/Containerfile +++ b/Containerfile @@ -1,13 +1,14 @@ -FROM golang:1.18 as builder +FROM golang:1.20-alpine as builder WORKDIR /go/src/app COPY . . -RUN apt update && apt upgrade -y -RUN go build +#RUN apt update && apt upgrade -y +RUN CGO_ENABLED=0 go build FROM alpine:latest as final WORKDIR /srv/ RUN mkdir /srv/dota_patch_bot -RUN mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2 +RUN apk add libc6-compat +#RUN mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2 COPY --from=builder /go/src/app/dota_patch_bot /srv/dota_patch_bot/ CMD ["/srv/dota_patch_bot/dota_patch_bot"] diff --git a/main.go b/main.go index 09403c4..b1c64ff 100644 --- a/main.go +++ b/main.go @@ -5,7 +5,7 @@ import ( "encoding/json" "flag" "fmt" - "io/ioutil" + "io" "log" "net/http" "os" @@ -37,7 +37,7 @@ func loadPatches(pl *patchList, url string) { } defer res.Body.Close() - body, readErr := ioutil.ReadAll(res.Body) + body, readErr := io.ReadAll(res.Body) if readErr != nil { log.Fatal(readErr) } @@ -48,7 +48,6 @@ func loadPatches(pl *patchList, url string) { } func notify(ptch patch, url string) { - type Payload struct { Text string `json:"text"` Format string `json:"format"` @@ -96,9 +95,12 @@ func notify(ptch patch, url string) { if err != nil { log.Println("error posting to webhook") } - defer resp.Body.Close() + if resp.Body != nil { + resp.Body.Close() + } } } + func main() { hookPtr := flag.String("hook", "", "the webhook to notify") sourcePtr := flag.String("url", "https://www.dota2.com/datafeed/patchnoteslist", "url to fetch patchnotes from") @@ -147,5 +149,4 @@ func main() { } } } - }