From 6eff27a8ffca34bbc8ed1a09391ef6cbeb10cc77 Mon Sep 17 00:00:00 2001 From: Michael Grosser Date: Tue, 4 Jun 2024 21:18:52 -0700 Subject: [PATCH] change Version to only have pointer receivers --- version.go | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/version.go b/version.go index a1f2414..a4ab4b9 100644 --- a/version.go +++ b/version.go @@ -240,7 +240,7 @@ func MustParse(v string) *Version { // See the Original() method to retrieve the original value. Semantic Versions // don't contain a leading v per the spec. Instead it's optional on // implementation. -func (v Version) String() string { +func (v *Version) String() string { var buf bytes.Buffer fmt.Fprintf(&buf, "%d.%d.%d", v.major, v.minor, v.patch) @@ -260,32 +260,32 @@ func (v *Version) Original() string { } // Major returns the major version. -func (v Version) Major() uint64 { +func (v *Version) Major() uint64 { return v.major } // Minor returns the minor version. -func (v Version) Minor() uint64 { +func (v *Version) Minor() uint64 { return v.minor } // Patch returns the patch version. -func (v Version) Patch() uint64 { +func (v *Version) Patch() uint64 { return v.patch } // Prerelease returns the pre-release version. -func (v Version) Prerelease() string { +func (v *Version) Prerelease() string { return v.pre } // Metadata returns the metadata on the version. -func (v Version) Metadata() string { +func (v *Version) Metadata() string { return v.metadata } // originalVPrefix returns the original 'v' prefix if any. -func (v Version) originalVPrefix() string { +func (v *Version) originalVPrefix() string { // Note, only lowercase v is supported as a prefix by the parser. if v.original != "" && v.original[:1] == "v" { return v.original[:1] @@ -298,8 +298,8 @@ func (v Version) originalVPrefix() string { // it unsets metadata and prerelease values, increments patch number. // If the current version has any of prerelease or metadata information, // it unsets both values and keeps current patch value -func (v Version) IncPatch() Version { - vNext := v +func (v *Version) IncPatch() Version { + vNext := *v // according to http://semver.org/#spec-item-9 // Pre-release versions have a lower precedence than the associated normal version. // according to http://semver.org/#spec-item-10 @@ -321,8 +321,8 @@ func (v Version) IncPatch() Version { // Increments minor number. // Unsets metadata. // Unsets prerelease status. -func (v Version) IncMinor() Version { - vNext := v +func (v *Version) IncMinor() Version { + vNext := *v vNext.metadata = "" vNext.pre = "" vNext.patch = 0 @@ -337,8 +337,8 @@ func (v Version) IncMinor() Version { // Increments major number. // Unsets metadata. // Unsets prerelease status. -func (v Version) IncMajor() Version { - vNext := v +func (v *Version) IncMajor() Version { + vNext := *v vNext.metadata = "" vNext.pre = "" vNext.patch = 0 @@ -350,8 +350,8 @@ func (v Version) IncMajor() Version { // SetPrerelease defines the prerelease value. // Value must not include the required 'hyphen' prefix. -func (v Version) SetPrerelease(prerelease string) (Version, error) { - vNext := v +func (v *Version) SetPrerelease(prerelease string) (Version, error) { + vNext := *v if len(prerelease) > 0 { if err := validatePrerelease(prerelease); err != nil { return vNext, err @@ -364,8 +364,8 @@ func (v Version) SetPrerelease(prerelease string) (Version, error) { // SetMetadata defines metadata value. // Value must not include the required 'plus' prefix. -func (v Version) SetMetadata(metadata string) (Version, error) { - vNext := v +func (v *Version) SetMetadata(metadata string) (Version, error) { + vNext := *v if len(metadata) > 0 { if err := validateMetadata(metadata); err != nil { return vNext, err @@ -466,7 +466,7 @@ func (v *Version) UnmarshalJSON(b []byte) error { } // MarshalJSON implements JSON.Marshaler interface. -func (v Version) MarshalJSON() ([]byte, error) { +func (v *Version) MarshalJSON() ([]byte, error) { return json.Marshal(v.String()) } @@ -483,7 +483,7 @@ func (v *Version) UnmarshalText(text []byte) error { } // MarshalText implements the encoding.TextMarshaler interface. -func (v Version) MarshalText() ([]byte, error) { +func (v *Version) MarshalText() ([]byte, error) { return []byte(v.String()), nil } @@ -505,7 +505,7 @@ func (v *Version) Scan(value interface{}) error { } // Value implements the Driver.Valuer interface. -func (v Version) Value() (driver.Value, error) { +func (v *Version) Value() (driver.Value, error) { return v.String(), nil }