viblo.asia viblo.asia

Microservice with go-kit Part II

In part I we've learned the concept of how Microservice worked and also how Go Kit fit into the design. In this part lets put it into practice by implementing a simple random sentence generator service. Service Lets start from our business logic by define and implement a service, basically a contract. For the purpose of this example our service will has one simple method which take n number of setences to return and return n random...

viblo.asia viblo.asia

Golang: Template

Getting Start The Go standard library provides a set of packages to generate output. The text/template package implements templates for generating text output, while the html/template package implements templates for generating HTML output that is safe against certain attacks. Both packages use the same interface but the following examples of the core features are directed towards HTML applications. Parsing To create and store a...

viblo.asia viblo.asia

Debugging Golang App Part II

Preface In the last post I've talked about how we can debug Golang application by using logging. This is great and all, but one frustrating problem I've found about debugging error message in Go was that I don't know what caused the error and where it came from. No Context Because the way Go treat error as value, when error occurred it didn't have stack trace information and to make thing worse error usually bubbled up from deep within...

viblo.asia viblo.asia

Debugging Golang App

Debugging is an essential part of software development. Coming from a dynamic world of Ruby like myself where one can just drop in binding.pry or byebug and play around with context, debuging in Golang is a bit ... daunting. So today I would like share a bit of what I found useful during my time of working with Golang. 1. fmt Package The most basic tool for printing value of variable in golang is fmt package. This package offers quite...

viblo.asia viblo.asia

Golang Unit Testing

Testing is a crucial part of software development and Go support for testing was built right into the language itself by providing a testing packages along with the command line tool, go test, to run test suites. The standard tool-chain also includes benchmarking and statement based code coverage. 1. Unit Testing Coming from the other languages, testing in Go might feel a little bit out of place as the syntax deliberately avoids the...

viblo.asia viblo.asia

Putting Together a Golang App IV

Preface In Part III we have implemented a bunch of things like middleware, making model and migration, how to use query scope, wrote some common utility functions and well as introduce api endpoint to list and show manga. In this part we will add support for creating and updating manga to our api as well as take a look at how to validate and bind request payload in golang. Handler Functions As usual lets start by working on the end...

viblo.asia viblo.asia

Putting Together a Golang App Part II

Preface In Part I we've already setup some basic routing and directory layout for our code base. In this part we will focusing on configure our app for different environment, setup database connection as well as write some utility packages that we will be using throughout the whole app. Configuration First lets grab neccessary library by run the following command. Again to add dependency we use dep ensure -add. $ dep ensure -add...

viblo.asia viblo.asia

Putting Together a Golang App Part I

Introduction Being fast and simple gives Golang a very appealing attraction to developers. But being simple means that every decision must be made by developer; from organizing directory structure to database configuration to choosing application architecture ...etc. There are many debates as well as libraries to help you get the job done, but choosing one among that many can be tough so I though I could share with you which approach I...