How to send 204 No Content with Go http package?

According to the package docs:

func NoContent(w http.ResponseWriter, r *http.Request) {
  // Set up any headers you want here.
  w.WriteHeader(http.StatusNoContent) // send the headers with a 204 response code.
}

will send a 204 status to the client.


Sending 204 response from your script means your instance still need to run and cost you money. If you are looking for a caching solution. Google got it and it's called Edge Cache.

You only need to response with the following headers and Google will automatically cache your response in multiple servers nearest to the users (that is, replying with 204). This greatly enhance your site's speed and reduce instance cost.

w.Header().Set("Cache-Control", "public, max-age=86400")
w.Header().Set("Pragma", "Public")

You can adjust the max-age, but do it wisely.

By the way, it seems billing must be enabled in order to use Edge Cache