Using Go you can create the image files in runtime. Find the small list below to observe the cases where it might be useful.

  1. Favicon
  2. Pixel-tracker
  3. Placeholder
  4. Watermark
  5. Image resizing

1. Favicon

Often Go applications are considered as a server part for delivering content for internal and/or external services. It is good practice to have an external program (wrapper) that returns the response — a kind of getaway to give only the desired payload and, in particular, without web-specific requests. Under web-specific requests from the client to the server-side, I mean favicon requests and various manifests, which are usually considered more as “front-end” types of resources. That is, in most cases, the same specialists who do the “front-part” of the project and responsible for their work.

But what if your Go app is also able to give out favicons and manifests on its own. And not just take a static favicon and manifest file but generate/create these byte arrays in runtime. This will allow our application to not depend on these static files.

Of course you can send a static file in response:

func faviconHandler(w http.ResponseWriter, r *http.Request) {
   http.ServeFile(w, r, "relative/path/to/favicon.ico")
}
...
func main() {
    http.HandleFunc("/favicon.ico", faviconHandler)
}

#image #golang #watermark

Golang Image Generator in Runtime (favicon, watermark, resizing images)
4.70 GEEK