Redirecting stdout to /dev/null in Go

Yesterday was the six month anniversary since I started my new job.  It’s been busy and I’ve learned a lot.  One thing I had to start learning was the Go programming language (aka Golang).  Today I wanted to temporarily suppress the standard out, but searching the Internet didn’t come up with any concise solutions.  What I did was pretty simple, but seems to work.

Basically, I’m using a third party package to parse an ini file.  The code works fine, but it is very verbose and prints out several lines of information that end up cluttering my logs.  My solution was to simply redirect the standard out to /dev/null.  Here’s what my code ended up looking like:

func unmarshal(bytes []byte, info *InfoStruct) error {

    // Redirect standard out to null
    stdout := os.Stdout
    defer func() { os.Stdout = stdout }()
    os.Stdout = os.NewFile(0, os.DevNull)

    return ini.Unmarshal(bytes, info)
}

Hopefully the code is easy to follow.  The “InfoStruct” is just some struct for data that is in the ini file.  The “ini” prefix is for the third party package that I am using.

In my quick searching, I found various information about redirecting logs, redirecting command output, etc.  There were even some examples of redirecting the stdout, but none were exactly what I wanted and most were less concise.

 

Star Wars

Just some random ramblings about my memories of seeing various Star Wars films . . .

The Original Trilogy

The first Star Wars movie I saw was The Empire Strikes Back.  It is also the first movie I remember seeing in a theater.  I went with my parents and older sister to some theater in down town Brussels.  In all honesty, I don’t think I had much idea what was going on, but I do remember the experience of going to a movie as a family.

It was about two more years before I saw A New Hope.  It was on a trip to Berlin with my father and older sister (my younger sister had just been born and stayed home with my mother).  The apartment in which we stayed had a VCR and “A New Hope” was one of the available tapes.  Being older, I was able to better appreciate the movie.

It was the summer of 1983 when Return of the Jedi was released and at the time we were visiting family in Idaho.  My older sister and I went with a few cousins to see the show.  I was at a good age to enjoy the Ewoks and fondly remember the outing to see the show.

The Prequels

My experiences with the prequels are less interesting and less memorable.  Episode I was seen in Arizona while visiting my new sister-in-law.  A couple years later in Colorado I accidentally saw Episode II a week before it was officially released.  I still haven’t seen Episode III even though upstairs there is a Blu Ray disc containing the film (and it has been sitting there for several years now).

Post Lucas (aka The Disney Years)

The Force Awakens had it’s official release date of 18 December 2015, but I managed to get tickets to a 9:30pm showing on 17 December which happens to correspond with Boy#1’s birthday.  So as a birthday present I took Boy#1 and Boy#2 to experience a Star Wars movie in the theater for the first time.

I purchased six tickets for $75.60 to see Rogue One at 8:00pm on 15 December 2016–again one day before the official release.  The tickets were for me, Boy#1, Boy#2, Boy#3, friend of Boy#1, and friend of Boy#2.  The movie was satisfying, but what I remember most was getting to and from the theater.  We had gotten a fair amount of snow (for Oregon at least) and the minivan couldn’t make it up the hill to get out of the neighborhood so we bundled up and walked the two miles to see the show and then walked home with Boy#3 soldiering on without complaint even though he was half-asleep.

In October 2017 I purchased six tickets for the 9:30pm showing of The Last Jedi on 14 December–Boy#2 had a band concert that evening so the later show time was requisite.  So after the concert, the entire family zipped home for Boy#2 to change from his concert apparel and then we all headed to the theater.  This was the first opportunity my daughter had to experience a Star Wars movie in a theater; she fell asleep.

The release of Solo corresponded with my daughter’s birthday–she was not overly keen to see the movie, so we didn’t.  I expect I will see it sometime, but for now I remember not seeing the film.