Golang Http Middleware

Http Middleware

Http Middleware is a shared functionality, using that we can log every request, gzip every response and check a cache before doing some heavy processing. Http Middleware has a single responsibility; we can plug it in our app at the interface level, it doesn’t affect our coding style like another layer in our request handling cycle. It is a pluggable and self-contained code, if we really want middleware we can plug it or if don’t want just remove it.                         wsgi_middlewareUsing middleware in Golang is very simple, we have to use middleware between a ServeMux and application handlers. The Http Middleware function accepts a handler as a parameter and returns a handler so that we can directly register the Middleware function with the ServeMux.

Middleware Chaining

T_AspNetCoreStartup_02In Golang, we can create handler chain by nested middleware functions inside another function. We can share values and also pass errors from one handler to another using middleware chaining.


This is an example of middleware chaining; we are passing the handler to “middlewareOne” as a variable, then transfer the control to the next “middlewareTwo” and then finally “loggingHandler”. This is necessary to know the control flow of middleware handlers, chain with other middleware handlers.

In Golang we can use Http Middleware for some specific handlers, no need to use it for all handlers. There are some third-party packages offers such kind of facilities.

Third-Party Middleware                                  

In Golang, we can use third-party package middleware instead of using our own middleware all the time. Well known third-party packages are Gorilla’s package and Negroni package.


The Gorilla package has collection handler for use with Golang’s net/http package. It mainly offers handler for logging, compressing http request and responses, validating content types.

Negroni provides an idiomatic approach to use Http Middleware in Golang. It supports to use net/http handlers, and also offers a way to handle Http Middleware. Negroni package offers middleware functions for logging handlers and to use the middleware functions some specific routes.


The Http Middleware is one of the advantage in Golang, by using this we can log each http request, gzip all responses and also we can check the cache before doing some heavy processing. The flow control of middleware handler is very useful and effective, also we can use middleware functions for specific routes.


Summary of “Golang”


For the past few days I was engaged in learning a new programming language called “Golang”, it’s a simple programming language for developing robust scalable software applications. I have explored many new things in the learning session.  I would like to share my ideas and my learning experiences On Golang programming language.

Go Vs other programming languages?


Golang is a general purpose programming language which can compete with C and C++ languages, Go has a simple syntax with a minimum set of standard key words, the interesting thing with Go is, one can build complex applications, with simple programming model. We can put our effort in higher level abstract things. When we look the syntax of Golang, it eliminates lot of standard which are usual in C#, Java or C++. Go inherits many concepts from C language. To give few example, like how simple the language is, we don’t need to specify a semicolon (;) to terminate the line, no access modifiers in Golang. We can do it by declaring the function name starting with upper case or lower case. Most important things are, its compilation time is much faster than other languages, and even compiling very large projects is done in few minutes.

Generally, it eliminates some standard patterns from Programming Language Theory, the language designers have made it simpler to achieve more performance in critical real world application. The compiler directly converts from high level language to machine language, i.e. we don’t need any intermediate steps like JVM for Java, so the compiler quickly builds the application. Once the basic syntax in “Golang” is familiarized, we can develop application with its inbuilt standard packages without depending on any 3rd party Frameworks/tools.

Go for Fresher’s than experienced developers


I would say comparatively Golang will be more attractive to the fresh software engineers than the experienced developers, because when we start working with Golang its provide very simple syntax to concurrent programs. The learning curve is bit faster, but for the experience developers it will take some time to understand the core benefits of Golang programming language because for the past few years If someone developed their real world application using Microsoft technologies or any other technologies, it will not be so easy to quickly adapt this new language, it will take some time to understand the language features. Once core concepts are understood, one can build real world applications.

“Unlearn something to learn new things”

Go syntax is really different than other programming language, for example: We don’t need while loop but we can achieve the same thing via “for” loop, so by learning one looping statement we can do the same thing what we did for other programming languages, so it gives flexibility to build the application.

Concurrency with GO


I have learned concurrency mechanism in this session. It is one the core feature of GO, very useful and we can use the standard library packages rather than using any additional packages like a TPL and so on, with simple keyword we can execute multiple function concurrently using the keyword “go” calling a routine, so the go routines will be running independently and automatically, this will increase the performance as well, here the channel is playing the important roll to synchronize the go routines.

Go with Interfaces

Go provide language features like interface and inheritance. Similar concepts like in other languages, we achieve the same thing what we achieve in other programming languages like C#, which means I would not say Go programming language is perfect object oriented programming languages.

Comparing to other Object Oriented languages. Go is much simpler, for defining the interfaces and types and implementing those interfaces by concrete methods on respective struct, so the compiler will check who are all implementing those methods from the Interface, they can have an access to the interfaces. Its bit difficult to grasp or understand the things who came from traditional object oriented programming.

Go With Web

We can create web application using standard library package called “http” and some sub packages as well, here the http middle ware stuffs is interesting to manage the shared functionalities, i.e. log the application trigger or any other authentication mechanism in the real world application and so on. JWT is also important concept to understand the token based message exchanging mechanism of JSON data across the client and server.  There are lot of built in packages available to extend the application and customize more.

Unit testing


This particular section was really interesting for writing unit test for our application, here we are simply using the “testing” shared library packages and start writing the unit testing, for the assertion we can use Omega packages, but we don’t want to mention the packages as well, there are lot of interesting points in the unit testing, because it provides some interesting features like “Benchmark” test, it is really useful to benchmark the flow and produce the average result across different scenario, another interesting things is we can run the unit tests in  parallel and can skip some long running unit tests using a flag by command line.


Overall the session was really useful to understand the concept of new programming language and to understand why its differ from other languages and so on, for me the interesting features which attracted myself to GOLANG   is its concurrency, channels, interfaces, inheritance, unit testing, packages, so overall Go is a language, easy to learn for fresher’s compare to the other experienced developers, because they can quickly understand and adopt. An experienced C# developer, will take some time to understand the changes, if someone is open minded and willing to unlearn some standard programming concepts he learned and practiced in Java or C#.

One needs to put some more effort and change the way he programs to speed up the learning process and use Go for building complex robust scalable solutions.

Thanks to Mr. Siju Varghese, Solution Architect who specializes in Go cloud and Docker.

Summary of Ramarson’s visit at Drupa2016 Germany.

IMG_20160605_140821 - Copy

Participating in such a global event is a real pleasure, the energy experienced in various halls were outstanding, one could feel the positive vibration everywhere. The level of enthusiasm and engagement was tremendous. As a techno entrepreneur I was very much excited to participate in the event.


My first visit was to our PalisProof machine placed in Bosch Rexroth booth, I felt proud to see the machine in the booth, there was tremendous response from  Germany, China, India, and Other European countries, Thanks to our operators who were kind and friendly in answering all the questions to the visitors.

As anyone who visited Drupa 2016 would agree; One of the highlight this year was Landa’s Theater shows, where they presented the nano inks/technology and nano printing, It was amazing to see their concept, instead of printing directly  on the substrate, print on Conveyor belt, remove the water or dry and transfer the image to the substrate. IMG_20160603_104648Their user interface concept of “21 century cockpit“, was very interesting to see and to learn. I could not see their real printing and look in to their print quality, then comes the KOMORI machines, Thanks for the technical guys who were kind enough in answering all the interesting technology questions I had,


The workflow solutions from Heidelberg was interesting to See, But that also triggered to talk with Kodak Prinergy and HP PrintOS platform.


HP PrintOS platform is a cloud platform for simplifying and automating production processes. it helps to improve operations & support collaboration. A cloud based  platform anytime, anywhere, very Interesting to learn the current developments.


I have seen the sample from KBA  and their current development.


Also attended various seminars, where the talks were about, how Industry 4.0 is applicable for printing Industry. What challenges are there to adopt, what is the current state in the adoption, like security, etc.,. They shared  which companies are already adopting, it was a very informative  presentation from Cisco. There was also some good presentation about new business models by utilizing the power of digital technology/Software as a value creation tool, which gave new stimulating thoughts on new Business models.


It was a memorable experience to stay in Dusseldorf, the learning and networking experience was wonderful. This event has given the opportunity to know current technological advancements and market demands.


Over all it was great learning experience;

  • To benchmark ourselves and to know where we are in the market.
  • Study what solutions are coming up from various suppliers.
  • To know what are customer expectations to consider, when building solutions.
  • To see the recent developments from  Printheads manufactures like Fujifilm, Samba heads.
  • Know the latest development  on work-flow solutions,  web2print and value adding cloud based platforms.

Clean Coding

I would like to share my knowledge about clean coding practices in the software development.

Everyone can do the coding but we are not sure whether it’s a quality code or professional code, it become a habit of writing a clean code, programming is not only solving the problem but its telling what is the way we are choosing to solving the problem, is that aspects clean coding is playing one of the major role in the software development.


In my point of view clean code should bring the following points.

  • Other developers can understand what we have written.
  • Extendibility.
  • Avoid duplication.
  • ……
  • …..

Simple example


The above is doing the addition operation, it should work but it’s not professional coding practices, I have to ask few questions like what is a, b and Do? and so on.


What about this code? Everyone can easily understand what it is doing and so on, so this is one of the ways of writing the clean code.

Always we have to keep in mind the following things while writing the coding.

  • Proper naming (class, methods, members, properties and so on).
  • Documentation.
  • SOLID principles.
  • Think about future.
  • Write unit tests.
  • Refactor if it’s not readable.
  • Put the classes in the proper namespace.
  • Consistency
  • Culture independent.
  • Machine independent.
  • Easy to configure the system.
  • Memory leaking issues.
  • Think about performance issues.
  • Error handling

Those points are very important and it’s not enough to write the professional code, we need to learn more about best practices and defining rules within the team and develop a code.


Initially it will be hard to follow all the points, but once love this and practice it, it will come naturally and you will become great professional developers.


Essential Lean: Waste at office


Introduction :

I wish to share this which I read through an image shared on Pinterest by http://www.100pceffective.com/  . Some of the minute things which we never considered and realized that it would affect our Productivity at our work place. And being played by us as a team lead , not only in our project but also on wasting of office time and things. Apparently we did not know that our colleagues and fellow members would watch us and indirectly adopt the same and follow us as their role models.

Here is some important stuff which we are unknowingly doing it and pave way for the fellow members and indirectly affects us being waste at office rather being productivity.

  1. Waiting:

According to current work environment most of us doesn’t like waiting as we need instant results and solutions for any problems never thinking that we are making others (may be any individual/ crew) to wait for a long time. Alright! I throw you few incidents that are very familiar which we have faced and we have done it.

Waiting for any official meeting to start, waiting for any discussion to start up as because of the participants were not on the right time seems to be Stealing other`s time . As per agenda we would not start and obviously we cannot end up, if the flow of the meeting was as per the agenda framed. In another instant the time delay for a computer to start up for the customer information we need.

  1. Transport:

Walking to meetings or travelling around the building or travelling around the building to collect or to meet any one. It doesn`t mean that we shouldn`t move anywhere leaving our seat, because some relaxation for mind and body is required.  I have seen people carrying file on hand and meet other departments and spend  half the day , But actually that much time is not needed for their discussion and meeting when you probe them.

We have to check whether the move that we make affects the work or not.

  1. Over processing:

we have a feeling and understanding  that when we say the word “documents” it needs to be neatly printed ,filed and shelved, which we cannot locate it at the right time when required and what`s the use of it doing so? Printing out documents which are unnecessary or printing of documents that we could read on screen.

Of course an office has to have some records and files, but we have to check for their priority, category and the usage of the same (how often we use that) if that same info is available at our desk.

  1. Inventory:

Holding of too much of stocks such as stationary or any other equipment that are purchased without knowing its frequency on usage. Things Like ball point pens, batteries, or the outdated products or documents or any other similar belongings of office.

Instead we can make a purchase list every month or a week (that depends upon the organization size and structure) and buy things accordingly based on the requirement

  1. Motion:

Getting up with a task to be done and end with the other one leaving assigned task, shift on the work which begins with shift over the thought during work which is again waste of time and affects our productivity.eg: Getting up to take the printed papers from the printer but look for files and heading to other work or another area to complete that.

Instead we can prioritize the daily work and go as per the schedule to avoid the shift and save time.

  1. Over Production:

Producing of too many products beyond the requirement and storing it is again a waste of man power and that affects the quality of the product when the actual demand is there. Working on the same type of document with multiple versions.

We can have a post production discussion to limit the production by setting a level/amount with respect to the product and its actual requirement with the respective management team.

  1. Defects/Rework:

Most of the defect and rework at work places falls on the following criteria, like misunderstanding on the actual requirement, lack of interest on listening others and entries of multiple inputs manipulating the systems developed or adopted. Either ruins the work and requires starting up again or ends with any defect that affects the quality.

Instead we can clarify ourselves where there is a misunderstanding on the requirements of the client or any work assigned  to us and then proceed. Confirm first the project or work requirements, get confirmed with the respective personnel and  then proceed.

  1. Employee Talent:

Besides all the above mentioned wastes at office this waste is considered to the predominant one according to my perspective. I believe that all other waste causing inabilities can be removed if a right talent is hired.  On the other hand training them by spending more time on a low level task which can be outsourced or done with other means. Also engaging employees on inappropriate task or the talent and skill of the employee hired is left unused or not used properly, remains a waste again.

Even though we all are aware of the things discussed, let us again refresh ourselves and analyze ourselves on the stuffs. As these are the Essential Lean six sigma concepts shared by the training bodies itself as mentioned on my introduction.

We can recycle all wastes of office into useful and productive features only when we accept and change our mind and adopt ourselves to be a person of 100% productivity.