Skip to content

Commit

Permalink
feat: fill in Go developer journey (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeagle authored Jan 1, 2025
1 parent 2cb268c commit 0ff0b9b
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion user_stories/go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,47 @@
# with the Go language enabled.
set -o errexit -o pipefail -o nounset

# Create/update the go.mod file
# The user writes some Go code with external imports
# Maybe they just search for "golang hello world"
# and paste the code found at https://yourbasic.org/golang/http-server-example/
# And then they also add an external dependency on
# https://pkg.go.dev/nmyk.io/cowsay just for fun.
mkdir -p cmd/hello
cat >cmd/hello/main.go <<EOF
package main
import (
"net/http"
"nmyk.io/cowsay"
)
func main() {
http.HandleFunc("/", HelloServer)
http.ListenAndServe(":8080", nil)
}
func HelloServer(w http.ResponseWriter, r *http.Request) {
cowsay.Cow{}.Write(w, []byte("Hello, world!"), false)
}
EOF

# Create/update the go.mod file, including the nmyk.io/cowsay dependency pinning
./tools/go mod tidy
# Update the BUILD files
bazel configure || true
# Run the application, starting a server
bazel run cmd/hello &
# Wait for the server
while ! nc -z localhost 8080; do
sleep 0.5
done

output=$(curl localhost:8080)
# Verify the application output matches expectation
[[ "${output}" =~ "Hello, world" ]] || {
echo >&2 "Wanted output containing 'Hello, world' but got '${output}'"
exit 1
}

# Shutdown server
kill %1

0 comments on commit 0ff0b9b

Please sign in to comment.