Post

Method Expressions

A method is a function associated to a type. The Go method declaration is a variation of a function declaration in which a initial parameter appears before the method name. The parameter has the type of the object designed to receive the method or is a pointer of that type. In this example the type Order has two methods, the AddProduct and the CalculateTotalCost . type Order struct {      Id int32      ProductList [] Product } func ( o * Order ) AddProduct( p Product ) {      o . ProductList = append ( o . ProductList , p ) } func ( o * Order ) CalculateTotalCost() ( cost float32 ) {      for _ , p := range o . ProductList {          cost += p . Price      }      return } We can call a method on an instance of the type Order or we...

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...