Post

Visualizzazione dei post da 2015

Go text and HTML templates

Template packages Server side languages offers a mechanism for inserting a dynamically generated content into static pages. Go provides a mechanism for substituting the value of variables into text or HTML template.  A Go template is string or file containing text (HTML) and  actions , that are string expressions enclosed in double braces {{ ... }} that trigger some behaviors. Actions are powerful notations for selecting and printing fields, expressing control flow and calling functions. Go standard library offers two package for managing templates: The packages share the same interface so the following examples that treat HTML can also be applied to simple text . text/template , implements data-driven templates for generating textual output html/template , is the same as text/template but automatically secures HTML output against certain attacks (script injection) Gin-Gonic Gin, the fast and full-featured web framework for Go that we have already seen in the GIF...

Deploy Microservice with Docker

Immagine
Docker Containers "Docker provides an integrated technology suite that enables development and IT operations teams to build, ship, and run distributed applications anywhere." Docker is an open source project that enables you to package any application in a lightweight, portable container. Docker has the ability to package applications in such a way that they can run anywhere. Docker is a powerful technology and it's supported with the majority of large public cloud. It is important to know that Docker is not a virtualization platform, it bases its operation on Linux Container. Docker provides many benefits when used properly: It facilitates the development and packaging of applications in a way that leverages the skills developers already have It allows developers to easily create test environments It simplifies the maintenance operations Check Docker installation This article does not explain how to install Docker, so refer to the documentation on the sit...

Provide a service for animated gif creation

Immagine
Animated GIF Service This example will provide a HTTP service that creates animated GIF containing the text that is passed as input to the service. The service uses the standard library of Go and some additional libraries: the image is produced using the standard library image the text written inside the image is generated using the library freetype ( https://github.com/golang/freetype ) the HTTP service is activated using the framework Gin-Gonic ( https://github.com/gin-gonic/gin ) What we get is a service that responds to requests like these http://localhost:8000/animated.gif?name=Max generating images like this Create the GIF Image The package image/gif provides all the methods and structures to operate with GIF image format. // Generate an animated gif func GenerateAnimation(text string , fontfile string , out io.Writer) {      const (          nframes = 64 // number of an...