From the command prompt, create a directory for your code called workspace.

$ mkdir workspace
$ cd workspace
Create the hello module:

$ mkdir hello
$ cd hello
$ go mod init example.com/hello
go: creating new go.mod: module example.com/hello
Add a dependency on the golang.org/x/example module by using go get.

$ go get golang.org/x/example
Create hello.go in the hello directory with the following contents:

package main

import (
    "fmt"

    "golang.org/x/example/stringutil"
)

func main() {
    fmt.Println(stringutil.Reverse("Hello"))
}
Now, run the hello program:

$ go run example.com/hello
olleH

Recommend

Go Tutorial: Getting started with multi-module workspaces Create a module for your code

Tutorial: Developing a RESTful API with Go and Gin Completed code

Tutorial: Developing a RESTful API with Go and Gin Write a handler to return a specific item Run the code

Tutorial: Developing a RESTful API with Go and Gin Write a handler to return a specific item Write the code

Tutorial: Developing a RESTful API with Go and Gin Write a handler to add a new item Run the code

Tutorial: Developing a RESTful API with Go and Gin Write a handler to add a new item Write the code

Tutorial: Developing a RESTful API with Go and Gin Write a handler to return all items Run the code

Tutorial: Developing a RESTful API with Go and Gin Write a handler to return all items Write the code

Tutorial: Developing a RESTful API with Go and Gin Create the data Write the code

Tutorial: Developing a RESTful API with Go and Gin Create a folder for your code

Go Tutorial: Accessing a relational database Completed code

Go Tutorial: Accessing a relational database Add data Write the code

Go Tutorial: Accessing a relational database Query for a single row Write the code

Go Tutorial: Accessing a relational database Query for multiple rows Run the code

Go Tutorial: Accessing a relational database Query for multiple rows Write the code

Go Tutorial: Accessing a relational database Get a database handle and connect Run the code

Go Tutorial: Accessing a relational database Get a database handle and connect Write the code

Go Tutorial: Accessing a relational database Find and import a database driver

Go Tutorial: Accessing a relational database Set up a database

Go Tutorial: Accessing a relational database Create a folder for your code

Go Tutorial: Getting started with generics Completed code

Go Tutorial: Getting started with generics Declare a type constraint Write the code

Go Tutorial: Getting started with generics Add a generic function to handle multiple types Write the code

Go Tutorial: Getting started with generics Add non-generic functions Run the code

Go Tutorial: Getting started with generics Add non-generic functions Write the code

Go Tutorial: Getting started with generics Create a folder for your code

Go Setting up and using gccgo C Interoperability Function names

Go Setting up and using gccgo C Interoperability Types

Go Setting up and using gccgo Imports

Go Setting up and using gccgo Using gccgo

Go Setting up and using gccgo Building Build commands

Setting up and using gccgo Building Gold

Installing Go from source Optional environment variables

Installing Go from source Keeping up with releases

Installing Go from source Install additional tools

Installing Go from source Testing your installation

Installing Go from source Install Go

Installing Go from source (Optional) Switch to the master branch

Installing Go from source Fetch the repository

Installing Go from source Install Go compiler binaries for bootstrap Bootstrap toolchain using gccgo

Installing Go from source Install Go compiler binaries for bootstrap Bootstrap toolchain from cross-compiled source

Go Managing dependencies Specifying a module proxy server

Go Managing dependencies Removing a dependency

Go Managing dependencies Getting a specific commit using a repository identifier

Go Managing dependencies Developing and testing against unpublished module code Requiring external module code from your own repository fork

Go Managing dependencies Developing and testing against unpublished module code Requiring module code in a local directory