Browsing all articles tagged with http | Brett Morrison - Official Site

GolangI’ve heard it’s never too late to learn a new language.  For spoken languages I’m not sure I agree, but for programming languages – of course!  The Go programming language started at Google in 2009, so I figured it’s about time I dug in with the Gopher.  Go is “almost” systems level, but it does have garbage collection, so language purists may dismiss it as a systems level language just based on that.  But with today’s processors, there’s a strong argument that Go can be a very successful all-purpose language.  I guess I was feeling retrospective after meeting Charles Petzold recently and thinking about how much C programming I did in the 90s.  His seminal, Programming Windows, was my daily bible study.  So, I thought, well I’m not going back to C after over a decade with C#, but let’s give Go a try!

I checked out the documentation, took an online course, and I was go for Go.  One of my colleagues, Darren Warner, had a recent devops task to connect to BitBucket’s API, iterate through the repos, and return status and information on any open Pull Requests.  He wrote it Python – and it was a perfect porting candidate for diving into Go.

Visual Studio Code running Go

I broke out Visual Studio Code (AKA Visual Studio Ultralight), and coded away.  My goal was for it to be as pure-native Go as possible, so I only used built-in Go standard library packages – no 3rd party add-ons.  I found the HTTP package to be great, works as it should – light, nice and async.  The JSON handling via maps are a bit verbose, and I’m sure I could re-factor some of that using any of the 3rd party JSON marshalling packages available, but again, I wanted to keep it as native and fast as possible.  I used proper error handling and create new err on every possible fail condition.

To run, simply:

> go run pullrequests.go --ownername="bitbucket-repo-owner-username" --username="my-bitbucket-username" --password="my-bitbucket-password"

Check out the complete code on GitHub or BitBucket!

 

 

Brett Morrison – Official Site

The official web site of Brett Morrison, Self-Made Technology Entrepreneur.

Links

No feed found with the ID 1. Go to the All Feeds page and select an ID from an existing feed.

Archives