-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add lassie user agent to default lipp2p host and http retriever…
… requests
- Loading branch information
1 parent
9292479
commit fecb692
Showing
9 changed files
with
160 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
/.vscode | ||
|
||
/cmd/lassie/lassie | ||
/lassie | ||
*.car | ||
|
||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
builds: | ||
- main: ./cmd/lassie | ||
binary: lassie | ||
ldflags: | ||
# Sets the version variable in the build package to the build version prefixed with a 'v' | ||
# Sets the main.date to a static date for checksum verification. See https://goreleaser.com/customization/builds/#reproducible-builds. | ||
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.CommitDate}} -X main.builtBy=goreleaser -X github.com/filecoin-project/lassie/pkg/build.version=v{{.Version}} | ||
goos: | ||
- linux | ||
- windows | ||
- darwin | ||
goarch: | ||
- 'amd64' | ||
- 'arm64' | ||
# Change to a static date for checksum verification. See https://goreleaser.com/customization/builds/#reproducible-builds. | ||
mod_timestamp: '{{.CommitTimestamp}}' | ||
universal_binaries: | ||
- replace: true | ||
archives: | ||
- format_overrides: | ||
- goos: windows | ||
format: zip | ||
- goos: darwin | ||
format: zip | ||
release: | ||
mode: keep-existing | ||
changelog: | ||
skip: true |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package build | ||
|
||
import "fmt" | ||
|
||
var UserAgent = fmt.Sprintf("lassie/%s", Version) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package build | ||
|
||
import ( | ||
_ "embed" | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/filecoin-project/lassie/pkg/internal/revision" | ||
) | ||
|
||
var ( | ||
defaultVersion string = "v0.0.0" | ||
// version is the built version. | ||
// Set with ldflags in .goreleaser.yaml via -ldflags="-X github.com/filecoin-project/lassie/pkg/build.version=v{{.Version}}". | ||
version string | ||
// Version returns the current version of the Lassie application | ||
Version string | ||
) | ||
|
||
func init() { | ||
if version == "" { | ||
// This is being ran in development, try to grab the latest known version from the version.json file | ||
var err error | ||
version, err = readVersionFromFile() | ||
if err != nil { | ||
// Use the default version | ||
version = defaultVersion | ||
} | ||
} | ||
|
||
Version = fmt.Sprintf("%s-%s", version, revision.Revision) | ||
} | ||
|
||
// versionJson is used to read the local version.json file | ||
type versionJson struct { | ||
Version string `json:"version"` | ||
} | ||
|
||
// readVersionFromFile reads the version from the version.json file. | ||
// Reading this should be fine in development since the version.json file | ||
// should be present in the project, I hope :) | ||
func readVersionFromFile() (string, error) { | ||
// Open file | ||
file, err := os.Open("version.json") | ||
if err != nil { | ||
return "", err | ||
} | ||
defer file.Close() | ||
|
||
// Decode json into struct | ||
decoder := json.NewDecoder(file) | ||
var vJson versionJson | ||
err = decoder.Decode(&vJson) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
// Read version from json | ||
return vJson.Version, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Package revision provides the vsc revision, embedded by the compiler, as a | ||
// global variable. | ||
package revision | ||
|
||
import ( | ||
"runtime/debug" | ||
) | ||
|
||
// Revision returns the revision embedded by the compiler during build. | ||
// Suffixed with "-dirty" if modified. | ||
var Revision string | ||
|
||
func init() { | ||
var revision string | ||
var dirty bool | ||
|
||
// Get the revision from the build info | ||
bi, ok := debug.ReadBuildInfo() | ||
if !ok { | ||
return | ||
} | ||
|
||
for _, bs := range bi.Settings { | ||
switch bs.Key { | ||
case "vcs.revision": | ||
revision = bs.Value | ||
if len(bs.Value) > 7 { | ||
revision = bs.Value[:7] | ||
} | ||
case "vcs.modified": | ||
if bs.Value == "true" { | ||
dirty = true | ||
} | ||
} | ||
} | ||
|
||
if dirty { | ||
revision += "-dirty" | ||
} | ||
|
||
Revision = revision | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters