Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gob: type semver.Version has no exported fields #192

Closed
bhaskarEEN opened this issue Dec 11, 2022 · 2 comments
Closed

gob: type semver.Version has no exported fields #192

bhaskarEEN opened this issue Dec 11, 2022 · 2 comments
Labels

Comments

@bhaskarEEN
Copy link

I get the above error when I try to encode a struct using the a variable of type semver.Version.
Example struct:

type Test struct {
	Version semver.Version `json:"version"`
	Name    string                 `json:"name"`
}

Example code to generate the above error:

package main

import (
	"bytes"
	"encoding/gob"
	"fmt"

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

type Test struct {
	Version semver.Version `json:"version"`
	Name    string         `json:"name"`
}

func main() {
	fmt.Println("Hello, 世界")

	val := Test{}
	gob.Register(val)
	v, _ := semver.NewVersion("1.2.3")
	val.Version = *v
	fmt.Printf("val: %+v\n", val)
	buf := bytes.Buffer{}
	enc := gob.NewEncoder(&buf)
	if err := enc.Encode(val); err != nil {
		fmt.Printf("Error while encoding: %v\n\n", err)
	}

	ver, _ := semver.NewVersion("1.2.3")
	gob.Register(ver)
	if err := enc.Encode(ver); err != nil {
		fmt.Printf("Error while encoding: %v\n\n", err)
	}
}
@mattfarina
Copy link
Member

What are you looking for?

@bhaskarEEN
Copy link
Author

Sorry, forgot the issue, I may have bypassed this somehow. Closing it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants