Last active
June 22, 2023 05:34
-
-
Save paambaati/be7dada31ad691939663210993035c63 to your computer and use it in GitHub Desktop.
Simple Go server that only prints version as response, a Dockerfile to quickly deploy it, and a k6 script that tests it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM golang:alpine AS builder | |
# Install git. | |
# Git is required for fetching the dependencies. | |
RUN apk update && apk add --no-cache git | |
WORKDIR $GOPATH/src/vserver/ | |
COPY . . | |
# Fetch dependencies. | |
# Using go get. | |
RUN go get -d -v | |
# Build the binary. | |
RUN GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o /go/bin/vserver | |
FROM scratch | |
COPY --from=builder /go/bin/vserver /go/bin/vserver | |
ENV SERVER_PORT=8080 | |
ENV SERVER_VERSION="1.0.0" | |
ENTRYPOINT ["/go/bin/vserver"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import http from "k6/http"; | |
export const options = { | |
vus: 1, | |
duration: "10m", | |
noConnectionReuse: true, | |
insecureSkipTLSVerify: true, | |
}; | |
export default function () { | |
const response = http.get("https://api.foldapp.dev/"); | |
console.log(new Date().toISOString(), "Running version: ", response.body) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"net/http" | |
"os" | |
) | |
func main() { | |
port, ok := os.LookupEnv("SERVER_PORT") | |
if !ok { | |
log.Fatal("$SERVER_PORT not set") | |
} | |
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | |
version, ok := os.LookupEnv("SERVER_VERSION") | |
if !ok { | |
http.Error(w, "$SERVER_VERSION not set", http.StatusInternalServerError) | |
return | |
} | |
fmt.Fprintf(w, "%s", version) | |
}) | |
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%s", port), nil)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment