APIs/HTTP microservices helper packages

The list below are helper packages that one should look into before start implementing Golang APIs/microservices. Understanding how they work, building APIs and HTTP microservices should be relatively easy.


Convert Go Code to AWS Lambda function

Import lambda package by running go get -u Make the handler available for remote procedure call by AWS lambda and utilizing lambda.start method as depicted in the image below:

Building – For Windows 10 users

  1. set GO111MODULE=on
  2. RUN go get -u
  3. set GOOS=linux
  4. set GOARCH=amd64
  5. set CGO_ENABLED=0
  6. RUN go build -o main main.go
  7. COPY main and PASTE in build-lambda-zip directory
  8. RUN build-lambda-zip.exe -o main

Assuming that the above steps were followed one should end up with a file. Browse to AWS lambda from AWS console, create function and upload the new zip file. Make sure that the code does not require any permissions that needs access to other AWS services.

Give it a try

Configure the test events and run a test.

The below shows a successful attempt where “finished” is returned from the code that we built above.


Go dep installation on Windows 10

Install Chocolatey from the following link – Head to Install with cmd.exe, copy command text, open cmd.exe with administrator rights and paste the command text and hit enter.

After a successful installation, paste the following command “choco install dep” and hit enter. “Do you want to run script?” will be prompted, with options to proceed. Typing ‘A’ (Yes to all) will run the script successfully.

After successful installation, type ‘dep version’. If the version is returned then it means that dep has installed successfully. Let’s go dep! 😉


Let’s GO

Install and download GO by following the link

Install and download VS Code ( lightweight and free ) or Goland ( requires a licence ) I used both – Goland is a winner as it makes our life much easier.

Let’s write our first boring hello world:

How do we run the code in our project? Navigate to the project directory and type go run filenamewewanttoexecute in this case the file is main.go

What does package main in line 1 mean? A package is a collection of common source code files. There are two types of packages – executable or reusable. In this case, package main creates an executable file when we ran go run main.go. func main() is required with package main.

What does import “fmt” in line 3 mean? is the name of a standard library package that it is included in the GO programming language by default. By importing means give the package main access for all the code and all the functionality that is contained into the “fmt” package.

What is func main()? func tells GO that we are going to declare a function whereas main is the name of the function. Parameters to a function are passed in ().