.:: mkdevs.eu ::.

Use external package with GO

Goals

At the end of this article you'll known how to:

Let's GO

To search a package, visit pkg.go.dev

Go to you sandbox or whatever working directory and create a use-ext-package sub directory

$ mkdir use-ext-package
$ cd use-ext-package

Then, enable dependency tracking for your code

$ go mod init learn/use-ext-package
go: creating new go.mod: module learn/use-ext-package

Using your favorite text editor, create a file use-ext-package.go in which to write your code.

Paste the following code into your use-ext-package.go file and save the file.

package main

import "fmt"
import "rsc.io/quote"

func main() {
    fmt.Println(quote.Go())
}

Then, add new module requirements and sums.

$ go mod tidy
go: finding module for package rsc.io/quote
go: downloading rsc.io/quote v1.5.2
go: found rsc.io/quote in rsc.io/quote v1.5.2
go: downloading rsc.io/sampler v1.3.0
go: downloading golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c

Finally, run your code to see the message generated by the function you're calling

$ go run .
Don't communicate by sharing memory, share memory by communicating.