mirror of
https://github.com/imjasonh/terraform-playground
synced 2026-07-21 23:08:12 +00:00
cf-worker-container
Signed-off-by: Jason Hall <jason@chainguard.dev>
This commit is contained in:
parent
51ee9aa0ec
commit
9ba46672ce
10 changed files with 965 additions and 0 deletions
28
cf-worker-container/main.go
Normal file
28
cf-worker-container/main.go
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
|
||||
"github.com/chainguard-dev/clog"
|
||||
"github.com/sethvargo/go-envconfig"
|
||||
)
|
||||
|
||||
var env = envconfig.MustProcess(context.Background(), &struct {
|
||||
Port string `env:"PORT,default=8080"`
|
||||
Message string `env:"MESSAGE,default=Hello from Go container!"`
|
||||
InstanceID string `env:"CLOUDFLARE_DURABLE_OBJECT_ID"`
|
||||
}{})
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
clog.InfoContext(ctx, "handling request", "path", r.URL.Path, "method", r.Method)
|
||||
fmt.Fprintf(w, "Hi, I'm a Go container! Message: \"%s\", Instance ID: %s\n", env.Message, env.InstanceID)
|
||||
})
|
||||
if err := http.ListenAndServe(":"+env.Port, nil); err != nil && err != http.ErrServerClosed {
|
||||
slog.Error("server error", "error", err)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue