From 0c9b5c54f5011f0de364af4aaa45d57d49090d94 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Fri, 28 Jul 2023 15:08:28 -0400 Subject: [PATCH] outyet: update example, make a separate module We want to revive golang.org/x/example as a test case for an experiment with a 'gonew' command. This CL updates outyet to be a gonew-able sample server, by making it its own module. The CL also removes Dockerfile and containers.yaml because I think the best practices around those files have evolved too much since 2015 when they were written. Change-Id: I53faf4b30de9e4ef3bfe35a781732daa140a9877 Reviewed-on: https://go-review.googlesource.com/c/example/+/513998 TryBot-Result: Gopher Robot Run-TryBot: Russ Cox Auto-Submit: Russ Cox Reviewed-by: Cameron Balahan --- README.md | 15 +++++++++++++++ outyet/Dockerfile | 2 -- outyet/containers.yaml | 8 -------- outyet/go.mod | 4 ++++ outyet/main.go | 3 ++- 5 files changed, 21 insertions(+), 11 deletions(-) delete mode 100644 outyet/Dockerfile delete mode 100644 outyet/containers.yaml create mode 100644 outyet/go.mod diff --git a/README.md b/README.md index 253a18f..88aa3ed 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,21 @@ The [reverse](hello/reverse/) reverse covers: * Conversion between string and []rune * Table-driven unit tests ([testing](//golang.org/pkg/testing/)) +## [helloserver](helloserver/) + +``` +$ cd helloserver +$ go run . +``` + +A trivial "Hello, world" web server. + +Topics covered: + +* Command-line flags ([flag](//golang.org/pkg/flag/)) +* Logging ([log](//golang.org/pkg/log/)) +* Web servers ([net/http](//golang.org/pkg/net/http/)) + ## [outyet](outyet/) ``` diff --git a/outyet/Dockerfile b/outyet/Dockerfile deleted file mode 100644 index 3fa58ff..0000000 --- a/outyet/Dockerfile +++ /dev/null @@ -1,2 +0,0 @@ -FROM golang:onbuild -EXPOSE 8080 diff --git a/outyet/containers.yaml b/outyet/containers.yaml deleted file mode 100644 index 44ba78a..0000000 --- a/outyet/containers.yaml +++ /dev/null @@ -1,8 +0,0 @@ -version: v1beta2 -containers: -- name: outyet - image: adg1/outyet - ports: - - name: http - hostPort: 80 - containerPort: 8080 diff --git a/outyet/go.mod b/outyet/go.mod new file mode 100644 index 0000000..720bbb4 --- /dev/null +++ b/outyet/go.mod @@ -0,0 +1,4 @@ +module golang.org/x/example/outyet + +go 1.19 + diff --git a/outyet/main.go b/outyet/main.go index ab251ba..496af2c 100644 --- a/outyet/main.go +++ b/outyet/main.go @@ -19,7 +19,7 @@ import ( // Command-line flags. var ( - httpAddr = flag.String("http", ":8080", "Listen address") + httpAddr = flag.String("http", "localhost:8080", "Listen address") pollPeriod = flag.Duration("poll", 5*time.Second, "Poll period") version = flag.String("version", "1.4", "Go version") ) @@ -30,6 +30,7 @@ func main() { flag.Parse() changeURL := fmt.Sprintf("%sgo%s", baseChangeURL, *version) http.Handle("/", NewServer(*version, changeURL, *pollPeriod)) + log.Printf("serving http://%s", *httpAddr) log.Fatal(http.ListenAndServe(*httpAddr, nil)) }