Skip to content

Commit

Permalink
Workaround for semver serealization (#26)
Browse files Browse the repository at this point in the history
Will be made obsolete when Masterminds/semver#228 is merged
  • Loading branch information
Andrew-Morozko committed Jan 8, 2024
1 parent 51868cc commit e323400
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
5 changes: 2 additions & 3 deletions pluginInterface/v1/plugin.go
@@ -1,7 +1,6 @@
package plugin

import (
"github.com/Masterminds/semver/v3"
"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/hcldec"
"github.com/zclconf/go-cty/cty"
Expand All @@ -24,7 +23,7 @@ type Plugin struct {
// "text", "plugin_a", etc.
Name string
// version of the plugin `Kind Name` that is provided by the current binary
Version semver.Version
Version Version
// Specification of the `config` block for this plugin
// If nil - providing a `config Kind Name` is an error
ConfigSpec hcldec.Spec
Expand All @@ -36,7 +35,7 @@ type Args struct {
// Specifies which kind, name and version of plugin to execute
Kind string
Name string
Version semver.Version
Version Version

// Result of decoding a config block with ConfigSpec
Config cty.Value
Expand Down
23 changes: 23 additions & 0 deletions pluginInterface/v1/semver.go
@@ -0,0 +1,23 @@
package plugin

import "github.com/Masterminds/semver/v3"

// semver.Version doesn't implement MarshalBinary/UnmarshalBinary required for
// gob (which is required by net/rpc, which is required by go-plugin).
// This is a temporary workaround, I expect they are going to add these methods
// after [my PR](https://github.com/Masterminds/semver/pull/228) is accepted

type Version semver.Version

func (v Version) MarshalBinary() ([]byte, error) {
return semver.Version(v).MarshalText()
}

func (v *Version) UnmarshalBinary(data []byte) error {
return (*semver.Version)(v).UnmarshalText(data)
}

// Returns the wrapped `semver.Version`.
func (v *Version) Cast() *semver.Version {
return (*semver.Version)(v)
}

0 comments on commit e323400

Please sign in to comment.