Handling Module in Go
Handling Module in Go
com/chap-18-go-module-proxies
• Forward Proxy
• Server / Client
2 Introduction
The go get command uses a proxy to fetch the latest releases of modules. In this section, we will detail how this proxy works.
• It will act as an intermediary between the clients and one or more servers.
A proxy server will receive requests for resources those request can for instance :
• forward it to the servers behind it (we call this kind of proxy server “Forward proxy”)
1 of 6 02/01/2023, 02:10
Go Module Proxies - Practical Go Lessons https://www.practical-go-lessons.com/chap-18-go-module-proxies
• Caching
◦ Instead of calling the server targeted, they will send a cached response to the client.
The paper and the digital edition of this book are available here. ×
I also filmed a video course to build a real world project with Go.
• A module can be deleted from the site sharing website by the developer.
If your application depends on this module building your Go application might be impossible.
The Go Command (go get) try to fetch modules from the proxy server
When the code is not available on the proxy server, Go can download it directly from the hosting server.
2 of 6 02/01/2023, 02:10
Go Module Proxies - Practical Go Lessons https://www.practical-go-lessons.com/chap-18-go-module-proxies
go env GOPROXY
you can check its current value. At the time of writing, the default value is :
https://proxy.golang.org,direct
“direct” : it instructs the tool to download it directly from the code hosting server.
Go will attempt to download new modules from each specified Go Module Proxy URLs from left to right. When it encounters the keyword
“direct” it will try to download the module directly from the source hosting website.
3 of 6 02/01/2023, 02:10
Go Module Proxies - Practical Go Lessons https://www.practical-go-lessons.com/chap-18-go-module-proxies
v1.0.0
v1.0.1
1. Ex : https://proxy.golang.org/ gitlab.com/loir402/bluesodium/@v/latest
{"Version":"v1.0.1","Time":"2021-01-20T18:49:34Z"}
/<module>/@v/<version>.info : get the metadata about the module’s version and the time at which it was committed.
{"Version":"v1.0.1","Time":"2021-01-20T18:49:34Z"}
The paper and the digital edition of this book are available here. ×
I also filmed a video course to build a real world project with Go.
go get -u modulePath
will not always download it immediately. The service has a cache in place to improve performance. Hence to solve this, you have two
solutions :
• Target specifically the version you want to use in the go get command
go get -u [email protected]
https://PROXY_URL/MODULE_PATH/@v/list
◦ Ex : https://proxy.golang.org/gitlab.com/loir402/bluesodium/@v/list
"https://proxy.golang.org/gitlab.com/loir402/bluesodium/v2/@v/list"
https://PROXY_URL/MODULE_PATH/@v/VERSION.zip
◦ Ex : https://proxy.golang.org/gitlab.com/loir402/bluesodium/@v/v1.0.1.zip
10 Test yourself
10.0.1 Questions
4 of 6 02/01/2023, 02:10
Go Module Proxies - Practical Go Lessons https://www.practical-go-lessons.com/chap-18-go-module-proxies
1. What is the name of the environment variable that controls the Go Module Proxy usage?
10.1 Answers
1. What is the name of the environment variable that controls the Go Module Proxy usage?
1. GOPROXY.
2. How to disable the usage of module proxies in a go get command?
Key takeaways
• A Go module proxy is a proxy server that will store Go modules’ code.
• Instead of downloading the source code directly from the code hosting server (ex: GitHub), the go command can download it from
the proxy server.
• Some modules might be unknown to the proxy; in that case, the server will generally add them afterward.
◦ For instance, the official Go Module Proxy has that system in place
• You can also deploy your own Go Module Proxy Server / or use a hosted alternative
• To use a specific proxy, you will have to modify the GOPROXY variable.
The paper and the digital edition of this book are available here. ×
I also filmed a video course to build a real world project with Go.
Bibliography
Previous Next
Table of contents
Did you spot an error ? Want to give me feedback ? Here is the feedback page! ×
Newsletter:
Like what you read ? Subscribe to the newsletter.
Practical Go Lessons
By Maximilien Andile
Copyright (c) 2023
Follow me Contents
Posts
Book
Support the author Video Tutorial
5 of 6 02/01/2023, 02:10
Go Module Proxies - Practical Go Lessons https://www.practical-go-lessons.com/chap-18-go-module-proxies
About
The author
Legal Notice
Feedback
Buy paper or digital copy
Terms and Conditions
6 of 6 02/01/2023, 02:10