Check reports whether the local binary's sha256 differs from the remote asset's recorded hash. ctx propagates a startup Ctrl+C into the HTTP request. Returns false on any failure; see package doc.
(ctx context.Context, execPath string)
| 54 | // asset's recorded hash. ctx bounds the HTTP request (the caller's update |
| 55 | // budget). Returns false on any failure; see package doc. |
| 56 | func Check(ctx context.Context, execPath string) bool { |
| 57 | if os.Getenv("CODEHAMR_NO_UPDATE_CHECK") == "1" { |
| 58 | return false |
| 59 | } |
| 60 | asset, ok := assetName(runtime.GOOS, runtime.GOARCH) |
| 61 | if !ok { |
| 62 | return false |
| 63 | } |
| 64 | local, err := hashFile(execPath) |
| 65 | if err != nil { |
| 66 | return false |
| 67 | } |
| 68 | remote, err := fetchHash(ctx, asset) |
| 69 | if err != nil || remote == "" { |
| 70 | return false |
| 71 | } |
| 72 | return !strings.EqualFold(local, remote) |
| 73 | } |
| 74 | |
| 75 | // assetName mirrors the name_template in .goreleaser.yaml. Every goos goreleaser |
| 76 | // builds for must have a case here; a missing one silently locks that |