terraform-provider-docker/scripts/testing/v1/main.go
Jonatan Reiners 09528d1c0e
chore: update Go version to 1.22 for consistency across workflows, jo… (#613)
* chore: update Go version to 1.22 for consistency across workflows, jobs, and modules.

* build: Update GitHub Actions setup-go and golangci-lint versions.

* refactor: Replace ioutil.ReadFile and ioutil.ReadAll with os.ReadFile and io.ReadAll.

* go fmt

* 🔄 Update actions/checkout and actions/setup-go to v4 and v5, respectively.

*  Refactor: Add b64 function to convert file to base64 in testacc_setup.sh.

*  Update Go version requirement in CONTRIBUTING.md.

*  Fix typo and improve error message format.

*  enhance: Improve error message in TestAccDockerContainer_uploadAsBase64.

*  Fix: Update file permissions for test2.txt in docker container tests.
2024-05-08 14:59:49 +02:00

45 lines
940 B
Go

package main
import (
"encoding/json"
"fmt"
"log"
"net/http"
"os"
)
const listenAddr = ":8080"
type config struct {
Prefix string `json:"prefix"`
}
func main() {
configsContent, err := os.ReadFile("configs.json")
if err != nil {
log.Fatalf("cannot open 'configs.json': %s", err)
}
var configs config
err = json.Unmarshal(configsContent, &configs)
if err != nil {
log.Fatalf("cannot unmarshal 'configs.json': %s", err)
}
http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
})
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
_, err = w.Write([]byte(fmt.Sprintf("%s - Hello World!", configs.Prefix)))
if err != nil {
log.Fatalln("failed to write for path '/'")
}
})
err = http.ListenAndServe(listenAddr, nil)
if err != nil {
log.Fatalf("failed to listen and server on port '%s'", listenAddr)
}
}