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

Add support for Go modules #5

Closed
nleiva opened this issue May 14, 2019 · 5 comments · Fixed by #47
Closed

Add support for Go modules #5

nleiva opened this issue May 14, 2019 · 5 comments · Fixed by #47
Assignees
Labels
enhancement New feature or request

Comments

@nleiva
Copy link
Collaborator

nleiva commented May 14, 2019

We need to migrate to Go modules (go.mod and go.sum). Pipeline is currently using Glide for dependency management which is no longer maintained.

In order to do so, we first need to remove the changes go generate makes to jsonpb as depicted in vendor.patch. EmitUInt64Unquoted is not part of the official protobuf library, so we need to replicate the Marshaler struct of github.com/golang/protobuf/jsonpb with this field on it. "A little copying is better than a little dependency".

I will first attempt to do this, before updating dependencies and bring Go 1.12 support as well.

@remingtonc
Copy link
Contributor

remingtonc commented May 24, 2019

@nleiva This appears to get more complex as we introduce modules. For example...

rm -rf vendor/
rm go.mod go.sum
export GO111MODULE=on
go mod init
go test -v ./

Errors out:

[pipeline-gnmi] go test -v ./                                                                                                               go-modules  ✗ ✭
# github.com/cisco-ie/pipeline-gnmi [github.com/cisco-ie/pipeline-gnmi.test]
./codec_gpb_test.go:33:3: unknown field 'EmitUInt64Unquoted' in struct literal of type jsonpb.Marshaler
./codec_gpb_test.go:39:3: unknown field 'EmitUInt64Unquoted' in struct literal of type jsonpb.Marshaler
FAIL    github.com/cisco-ie/pipeline-gnmi [build failed]

Fixing references:

# github.com/cisco-ie/pipeline-gnmi [github.com/cisco-ie/pipeline-gnmi.test]
./codec_gpb_test.go:35:3: cannot use promoted field Marshaler.EmitDefaults in struct literal of type Marshaler
./codec_gpb_test.go:36:3: cannot use promoted field Marshaler.OrigName in struct literal of type Marshaler
./codec_gpb_test.go:41:3: cannot use promoted field Marshaler.EmitDefaults in struct literal of type Marshaler
./codec_gpb_test.go:42:3: cannot use promoted field Marshaler.OrigName in struct literal of type Marshaler
FAIL    github.com/cisco-ie/pipeline-gnmi [build failed]

@remingtonc
Copy link
Contributor

Fixed function itself but a test is now failing which appears related to the unmarshaling.
Tracking in branch go-modules.

@remingtonc
Copy link
Contributor

I am especially inclined to look at #15 with these jsonpb issues.

@nleiva
Copy link
Collaborator Author

nleiva commented May 24, 2019

[pipeline-gnmi] go test -v ./                                                                                                               go-modules  ✗ ✭
# github.com/cisco-ie/pipeline-gnmi [github.com/cisco-ie/pipeline-gnmi.test]
./codec_gpb_test.go:33:3: unknown field 'EmitUInt64Unquoted' in struct literal of type jsonpb.Marshaler
./codec_gpb_test.go:39:3: unknown field 'EmitUInt64Unquoted' in struct literal of type jsonpb.Marshaler
FAIL    github.com/cisco-ie/pipeline-gnmi [build failed]

Yeah, codec_gpb_test.go still references to github.com/golang/protobuf/jsonpb. I forgot to make the changes in the test files (to reference the local jsonpb struct instead), my bad. I will fix this in the next couple of days.

# github.com/cisco-ie/pipeline-gnmi [github.com/cisco-ie/pipeline-gnmi.test]
./codec_gpb_test.go:35:3: cannot use promoted field Marshaler.EmitDefaults in struct literal of type Marshaler
./codec_gpb_test.go:36:3: cannot use promoted field Marshaler.OrigName in struct literal of type Marshaler
./codec_gpb_test.go:41:3: cannot use promoted field Marshaler.EmitDefaults in struct literal of type Marshaler
./codec_gpb_test.go:42:3: cannot use promoted field Marshaler.OrigName in struct literal of type Marshaler
FAIL    github.com/cisco-ie/pipeline-gnmi [build failed]

We cannot access the embedded or promoted fields in a struct literal. You either do it like you did:

marshallerEmitString := &Marshaler{
	EmitUInt64Unquoted: false,
	Marshaler: jsonpb.Marshaler{
		EmitDefaults: true,
		OrigName:     true,
	},
}

or

marshallerEmitString := Marshaler{}
marshallerEmitString.EmitUInt64Unquoted = false
marshallerEmitString.EmitDefaults = true
marshallerEmitString.OrigName = true

@nleiva
Copy link
Collaborator Author

nleiva commented May 24, 2019

Fixed function itself but a test is now failing which appears related to the unmarshaling.
Tracking in branch go-modules.

I'll take a look at it.

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

Successfully merging a pull request may close this issue.

2 participants