Now, to properly release these modules we’d need to make a release of the golang.org/x/example module, for example at v0.1.0. This is usually done by tagging a commit on the module’s version control repository. See the module release workflow documentation for more details. Once the release is done, we can increase the requirement on the golang.org/x/example module in hello/go.mod:

cd hello
go get example.com/dep@v0.1.0
Now, to properly release these modules we’d need to make a release of the golang.org/x/example module, for example at v0.1.0. This is usually done by tagging a commit on the module’s version control repository. See the module release workflow documentation for more details. Once the release is done, we can increase the requirement on the golang.org/x/example module in hello/go.mod:

cd hello
go get example.com/dep@v0.1.0
Modify the contents of workspace/hello/hello.go to contain the following contents:

package main

import (
    "fmt"

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

func main() {
    fmt.Println(stringutil.ToUpper("Hello"))
}
From the workspace directory, run the git command to clone the repository:

$ git clone https://go.googlesource.com/example
Cloning into 'example'...
remote: Total 165 (delta 27), reused 165 (delta 27)
Receiving objects: 100% (165/165), 434.18 KiB | 1022.00 KiB/s, done.
Resolving deltas: 100% (27/27), done.
The go work use command adds a new module to the go.work file. It will now look like this:

go 1.18

use (
    ./hello
    ./example
)
Add a new folder to the workspace/example/stringutil directory containing the following contents:

package stringutil

import "unicode"

// ToUpper uppercases all the runes in its argument string.
func ToUpper(s string) string {
    r := []rune(s)
    for i := range r {
        r[i] = unicode.ToUpper(r[i])
    }
    return string(r)
}
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"))
}
Create the hello module:

$ mkdir hello
$ cd hello
$ go mod init example.com/hello
go: creating new go.mod: module example.com/hello

Recommend

Go Tutorial: Getting started with multi-module workspaces Download and modify the golang.org/x/example module Run the code in the workspace

Go Tutorial: Getting started with multi-module workspaces Download and modify the golang.org/x/example module

Go Tutorial: Getting started with multi-module workspaces Create the workspace Initialize the workspace

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