Skip to content

feat: add info endpoint for data as json format#81

Open
danistrebel wants to merge 11 commits intoGoogleCloudPlatform:masterfrom
danistrebel:feature/json-endpoint
Open

feat: add info endpoint for data as json format#81
danistrebel wants to merge 11 commits intoGoogleCloudPlatform:masterfrom
danistrebel:feature/json-endpoint

Conversation

@danistrebel
Copy link
Copy Markdown

Problem Statement

Current implementation mainly targets an HTML based UI demo.

In my experience this makes the following use cases less elegant to demo:

  1. Authentication with just a simple cURL command
  2. Show load balancing distribution e.g. based on the color value in an automated capture.
  3. Call a service from a bastion host that can't show the rendered HTML page

Proposal

Add /info endpoint that directly outputs the existing data struct without the HTML template.

Demo

Service

K_SERVICE=foo K_REVISION=bar COLOR=my-color go run hello.go

Client

curl localhost:8080/info

response

{
  "Service": "foo",
  "Revision": "bar",
  "Project": "my-host",
  "Region": "europe-west1-d",
  "AuthenticatedEmail": "",
  "Color": "my-color"
}

Copy link
Copy Markdown
Member

@JulienBreux JulienBreux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! It's a very good and useful proposition.

Comment thread hello.go Outdated
http.HandleFunc("/info", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
encoder := json.NewEncoder(w)
encoder.SetIndent("", " ")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you want to use SetIndent on encoder? Just for cosmetic?
It's not better to use jq locally and keep json "compressed"?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me. Removed the SetIndent.

dependabot bot and others added 9 commits July 2, 2024 19:33
…udPlatform#84)

Bumps [github.com/cloudevents/sdk-go/v2](https://github.com/cloudevents/sdk-go) from 2.3.1 to 2.15.2.
- [Release notes](https://github.com/cloudevents/sdk-go/releases)
- [Commits](cloudevents/sdk-go@v2.3.1...v2.15.2)

---
updated-dependencies:
- dependency-name: github.com/cloudevents/sdk-go/v2
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps golang from 1.21 to 1.22.

---
updated-dependencies:
- dependency-name: golang
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Adam Ross <adamross@google.com>
…orm#88)

* docs: update README struct and include hello-job

* Update README.md: Clarify source code not containers in repo
The Continuous Deployment flow now allows to click the URL right away, so we can't assume the build has failed.
Copy link
Copy Markdown
Member

@JulienBreux JulienBreux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@JulienBreux
Copy link
Copy Markdown
Member

cc @steren @grayside for merging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants