Skip to content

Instantly share code, notes, and snippets.

@wilmoore
Last active July 25, 2024 03:59
Show Gist options
  • Select an option

  • Save wilmoore/6121941 to your computer and use it in GitHub Desktop.

Select an option

Save wilmoore/6121941 to your computer and use it in GitHub Desktop.
Software Engineering :: Programming :: Languages :: GoLang :: Your First Go Program

Software Engineering :: Programming :: Languages :: GoLang :: Your First Go Program

⪼ Made with 💜 by Polyglot.

research

create a project directory

% mkdir -p /tmp/starter
% cd !$

Create the source directory

% mkdir src

Use the golang asdf plugin to install GoLang

% asdf plugin add golang
% asdf install golang latest
% asdf global golang latest

Create a package / module

% mkdir -p src/$USER/hello
% go mod init wilmoore.com/hello

Add source file (src/$USER/hello/hello.go)

% cat > src/$USER/hello/hello.go <<EOF
package main

import "fmt"

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

Compile

% GOPATH=$PWD go install ./src/$USER/hello

Run binary

% ./bin/hello
#=> Hello, world.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment