Integrating logrus with cobra

You can find a working example on my GitHub: https://github.com/seblegall/blog-scripts/tree/master/logrus-cobra

I recently had to refactor the way one of my app print logs. My idea was to use logrus as it is a very well known lib to produce logs with Go.

Logrus let you print nicely color-coded and structured logs and is completely API compatible with the standard library logger.

logrus

My first question was about log level and how to setup it once across all sub-directory/package of my project.

Under the hood, logrus instantiate a new variable log. Once done, calling the logrus.SetLevel() function will store the level directly in this newly instantiated struct.

Thus, we have a global struct, available across all sub-package making the level automatically shared without having to use dependency injection.

If you need to set a different level in a sub-package (for example), you just need to instantiate a new logger :

1
2
3
4
5
var log = logrus.New()

//...

log.Debug("debug log")
[Read More]
Go  logrus  cobra 

The bottom-up performance review

performance review

The performance review is a common way to regularly give or get feedback about the work that has been done. Some company performs those once a year, other twice a year. Agile teams may do it more frequently. In my previous experiences, the retrospective we were doing after each sprint was a way to give personal feedback and once a year we were doing a yearly retrospective to summarize the whole past year, as a team.

[Read More]

A Makefile based CI/CD chain for Go

lunch button

Whatever the project you are working on, whatever the programming language, using a Makefile to handle common tasks is a great idea.

Makefiles are great at :

  • Mask the complexity of a task;
  • Handle multiple tasks;
  • Help contributors to start with your project;
  • Manage configuration using env var;
  • Define a common interface / standard between projects;
  • Abstract the underlying technology.

For all those reasons, make is a perfect fit with any CI/CD chain. Using a Makefile helps you define a simple and common interface usable whatever the CI/CD chain you plan to use. The only thing you will have to worry about is that your CI/CD chain tool will call the right target.

1
make something

And the job is done. It could be done with Travis. It could be done with Jenkins. The only thing that matters is the interface defined by your targets.

makefile

[Read More]

Handling validation errors from API-Gateway with AWS Amplify using ReactJs

Recently, I’ve been working with AWS in order to experience how it is to build a MVP really quickly. The goal I’ve been trying to achieve is to use as much AWS tools as possible to get a working product in production the fastest. aws-amplify

To do that, I choose to rely on :

  • Lambda for back-end code
  • API-Gateway for REST API
  • DynamoDB as a database
  • Cognito to manage Singnin / Singup and authenticated calls to the API.
[Read More]

Building a really smart Jabber chatbot with Dialogflow

Have you heard of Dialogflow?

Dialogflow (previously known as api.ai) is a conversational agent manager. Basically, you can see Dialogflow as a back-office were to manage an NLP engine.

robots

As an admin, you can create intents that represent a suite of similar “user says”. Under the hood, Dialogflow provide an AI (Natural Language Processing) that learns to match user inputs (called “user says”) with intents depending on the context, in order to provide the more logical/appropriate response. It could be an actual answer, called a “speech”, as it can be an action. For example : starting a job, running a command, etc.

[Read More]
Go  Dialogflow  AI  NLP  Jabber  XMPP 

Form validation with React using Formik and Redux

Form handling is a huge web development topic. There are almost only 2 ways to deal with form, depending on the lib / the framework you choose to use and depending on the side you are trying to handle your form (client vs server) : The ones that include form handling a component. This component usually does a lot of magic and force you to think your form the way it is going to be handle by the component. [Read More]

Parsing code snippets from markdown with Go

Those time, I’ve been thinking that choosing the right vendor that fit your needs or will solve your problem has became a pain. With the growth of platforms like Github and dependencies management tools (whatever the language) more and more people share their work and open source the peace of code they have created to solve a specific problem. That’s great ! But at the end… you find out that for a given problem you want to solve, their are tones of libs that claim to do the same thing but each in a different way. [Read More]