Files
athens/pkg/config/module.go
Nicholas Wiersma d932d50232 chore: lint code with golangci-lint (#1828)
* feat: add golangci-lint linting

* chore: fix linter issues

* feat: add linting into the workflow

* docs: update lint docs

* fix: cr suggestions

* fix: remove old formatting and vetting scripts

* fix: add docker make target

* fix: action go caching

* fix: depreciated actions checkout version

* fix: cr suggestion

* fix: cr suggestions

---------

Co-authored-by: Manu Gupta <manugupt1@gmail.com>
2023-02-24 20:39:17 -08:00

32 lines
831 B
Go

package config
import (
"fmt"
"path/filepath"
"strings"
)
// PackageVersionedName return package full name used in storage.
// E.g athens/@v/v1.0.mod.
func PackageVersionedName(module, version, ext string) string {
return fmt.Sprintf("%s/@v/%s.%s", module, version, ext)
}
// FmtModVer is a helper function that can take
// pkg/a/b and v2.3.1 and returns pkg/a/b@v2.3.1.
func FmtModVer(mod, ver string) string {
return fmt.Sprintf("%s@%s", mod, ver)
}
// ModuleVersionFromPath returns module and version from a
// storage path.
// E.g athens/@v/v1.0.info -> athens and v.1.0.
func ModuleVersionFromPath(path string) (string, string) {
segments := strings.Split(path, "/@v/")
if len(segments) != 2 {
return "", ""
}
version := strings.TrimSuffix(segments[1], filepath.Ext(segments[1]))
return segments[0], version
}