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

Need Help with Collections #32

Open
JonathanHo16 opened this issue Aug 25, 2022 · 3 comments
Open

Need Help with Collections #32

JonathanHo16 opened this issue Aug 25, 2022 · 3 comments

Comments

@JonathanHo16
Copy link

JonathanHo16 commented Aug 25, 2022

Hi I was wondering if someone could tell me what I am doing wrong here, the compiler tells me "missing type in composite literal" however, I don't know what do to fix it. I'm still kind of new to Go, gRPC, and protocol buffers. Code Snippet Below
practiceArray := []*proto.Value{ {Inner: &proto.Value_Int{Int: int64(data.M_suspensionPosition[0])}}, {Inner: &proto.Value_Int{Int: int64(data.M_suspensionPosition[1])}}, {Inner: &proto.Value_Int{Int: int64(data.M_suspensionPosition[2])}}, {Inner: &proto.Value_Int{Int: int64(data.M_suspensionPosition[3])}}, } var testCollection = &proto.Value_Collection{Collection: {Elements: practiceArray}} print(testCollection)

@mpenick
Copy link
Contributor

mpenick commented Aug 25, 2022

Fix code to make it viewable:

practiceArray := []*proto.Value{
        {Inner: &proto.Value_Int{Int: int64(data.M_suspensionPosition[0])}},
        {Inner: &proto.Value_Int{Int: int64(data.M_suspensionPosition[1])}},
        {Inner: &proto.Value_Int{Int: int64(data.M_suspensionPosition[2])}},
        {Inner: &proto.Value_Int{Int: int64(data.M_suspensionPosition[3])}},
    }
    var testCollection = &proto.Value_Collection{Collection: {Elements: practiceArray}}
    print(testCollection)

@mpenick
Copy link
Contributor

mpenick commented Aug 25, 2022

This is the fix:

&proto.Value_Collection{Collection: {Elements: practiceArray}} -->
&proto.Value_Collection{Collection: &proto.Collection{Elements: practiceArray}}

Full code (w/ fix):

	practiceArray := []*proto.Value{
		{Inner: &proto.Value_Int{Int: int64(data.M_suspensionPosition[0])}},
		{Inner: &proto.Value_Int{Int: int64(data.M_suspensionPosition[1])}},
		{Inner: &proto.Value_Int{Int: int64(data.M_suspensionPosition[2])}},
		{Inner: &proto.Value_Int{Int: int64(data.M_suspensionPosition[3])}},
	}
	testCollection := &proto.Value_Collection{Collection: &proto.Collection{Elements: practiceArray}} 
	print(testCollection)

@mpenick
Copy link
Contributor

mpenick commented Aug 25, 2022

The protobuf type can be quite verbose and can be a bit difficult to use. This project is working toward making the Go gRPC API easier to use: https://github.com/datastax-ext/astra-go-sdk. It's still early days, but maybe give it a try!

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

No branches or pull requests

2 participants