Skip to content

Commit

Permalink
docs: improve go mod proxy docs
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
  • Loading branch information
caarlos0 committed Apr 5, 2021
1 parent 324580c commit 41356ea
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions www/docs/cookbooks/build-go-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,28 @@ go build -o nfpm github.com/goreleaser/nfpm/v2/cmd/nfpm
This will resolve the source code from the defined module proxy using `proxy.golang.org`.
Your project's `go.sum` will be used to verify any modules that are downloaded, with `sum.golang.org` "filling in" any gaps.

## Getting the version from the module

You can also get the module version at runtime using [`debug#ReadBuildInfo`](https://pkg.go.dev/runtime/debug#ReadBuildInfo).
It is useful to display the version of your program to the user, for example.

```golang
package main

import (
"fmt"
"runtime/debug"
)

func main() {
if info, ok := debug.ReadBuildInfo(); ok && info.Main.Sum != "" {
fmt.Println(info)
}
}
```

You can also use `go version -m my_program` to display the go module information.

## Limitations

1. Extra files will still be copied from the current project's root folder and not from the proxy cache;
Expand Down

1 comment on commit 41356ea

@vercel
Copy link

@vercel vercel bot commented on 41356ea Apr 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.