Your first Go application

Programming in GO is quick and fun. You can write a working, compiled application with a few lines of code.

Write your first Go application

  • Create a directory of your application, let’s call it my-app
  • Open a terminal window in the my-app directory
  • To create two sub-directories, execute
    mkdir -p cmd/my-app
    mkdir pkg
  • Start the Atom text editor in the my-app directory with the command (include a dot at the end of the command)
    atom .
  • In Atom right-click the cmd/my-app directory and select New File
  • Name the file my-app.go
  • Copy the following code into the file
    package main

    import "fmt"

    func main() {
    fmt.Println("Hello World!!!")
  • Save the file
  • To run the application execute the command in the terminal window
    go run cmd/my-app/my-app.go
  • The output should be
    Hello World!!!

Create a Git repository

  • Create a Git repository for the application and push the code to GitHub

Create a module for your application

In the main directory of your application execute

go mod init


Leave a comment

Leave a Reply