Houcksoft is a blog by Matthew Houck. Software engineer, blacksmith, writer, and general practitioner of obtaining way to many hobbies.

Lets Go! - An Introduction and Dialog on Golang

Recently I was challenged with a sample project for a development position that I have applied for. I have never used go before, and expressed that in a month or two I could likely get to a potentially capable level of skill for a development shop. And their request was that I create a simple REST api with a couple endpoints that would handle the following criteria

  1. One endpoint that would receive a task object in JSON. This task would be assigned an agent if one is available and return the task object with the associated agent in question.

  2. A task can have one or many skills required for the task and a priority

  3. An agent may only be assigned to the task if they have all the required skills for the task

  4. If no agents are available with the required skills, and the task if of a higher priority than currently assigned tasks, an agent will receive this higher priority task in addition to the existing task

  5. Tasks that override based on priority will prefer agents that have most recently received tasks.

  6. One endpoint to allow the task to be set as completed

This is a fairly straight forward set of requirements. The only challenges that I could see here were the override process and the skill set requirement process.

As I normally use MSSQL for database operations, and since I was working with a new technology already, I decided to spend a bit more time on another technology that I have not used much previously: postgresql.

First things first

We need to head over and install the language on our environment and get a sample app going. You can head on over to the Golang site and get yourself an applicable install for your operating system of choice (I used windows on my laptop here).

Once created, we need to navigate to our %USERPROFILE%/go/src directory and create a new folder for our project. Keep in mind that the name of your directory is going to be the name of your app, and you will likely be typing this out quite a bit for building and running this app.

As with all intros to a language, we make a hello world to get an idea of if everything is running correctly and we have some code output. So I created a directory hello and used touch in gitbash to create our main.go file (entrypoint file for the app). The name of this entry point isn’t really important, but there are some requirements for your running app that we will touch on shortly.

hello_go.PNG

Within hello.go we have our basic code.

    package main

import "fmt"

func main() {
    fmt.Printf("hello, world\n")
}

Here we have two important requirements.

package main 

and

func main()    

These allow the language to know what our entry points are for the application. This isn’t required to be in the root of your application either. However the directory structures and preferences of project structure are still quite alien to me. So I kept it simple.

Next we just need to build and run the app:

hello_go_run.PNG

Now we know we are up and running, we have all of our ducks in a row, and we are ready to start tackling the next concept. Creating a REST api.

My next article will cover this in the near future. Check in next time for setting up our first routes with gorilla mux in go.

Till next time

~noodle

Google Cloud Platform (GCP) and finding TLS information for updates

Google Cloud Platform (GCP) and finding TLS information for updates

Super Basics - Permutations of Characters In A String