Episode #16 — Extracting and designing a generic interface — Golang

Avi Zurel
Fullstack Network
Published in
2 min readJun 6, 2017

--

Last night was a different session for me. Since Stephens Xu could not join me. I was doing the streaming session alone.

I’ve been working on Gong. For the first 10 minutes or so I’ve been thinking about what to work on, discussing different approaches. After a bit of a discussion I decided to refactor the code to be cleaner and extract a generic Client interface.

The reason for that is that I want the client to be replaced. You might have JiraClient or GithubIssuesClient. As long as you expose the same interface the system will just work.

The video

First pass on the client

type Client interface {
GetAuthFields() map[string]bool
GetName() string
FormatField(fieldName string, value string) string
}

The first pass exposed something interesting. Some clients might need fields that others don’t. For example the JiraClient requires a domain, username and password. Other clients might only need apiKey.

So the first method is to expose those fields into a map of string and bool. The string is the field name and the bool represents whether it should be masked in the terminal or not (passwords for example should not be exposed in the terminal *ever*)

Commits

After a bit of circling around during the stream, once I shut down the stream I was able to solve an issue I’ve been dealing with for the last 10 or so minutes of the stream.

Here are the commits done last night. Check out the code, the video and give feedback

I like this code much better than the previous iteration

My approach is always to have something that works *first*, refactor and make it better later.

After I have the initial thoughts and the interaction, I now know what to do better.

Next streams

We are going to continue streaming *every single day* this week.

You can find details about the stream schedule and where to find it in the post here:

--

--