How to use package from Gitlab?

Hi all

I’ve generated a go file from proto file and hosts on https://gitlab.com/silentdata/identity-contract.

Then I tried to create a gRPC server as follows:

package main

import (
    "context"
    "gitlab.com/silentdata/identity-contract/proto"
)

type server struct {

}

func (s *server) SignUp(ctx context.Context, in *Registration) (*Identity, error) {

}



func main() {

}

But the compiler complains:

./main.go:5:2: imported and not used: "gitlab.com/silentdata/identity-contract/proto"
./main.go:12:50: undefined: Registration
./main.go:12:66: undefined: Identity

I am using go mod to manage my modules and the folders are structured as follows:

enter image description here

The content of my go.mod file

module identity-service

go 1.14

require (
    github.com/golang/protobuf v1.3.4 // indirect
    github.com/google/uuid v1.1.1 // indirect
    github.com/labstack/echo/v4 v4.1.14 // indirect
    github.com/mattn/go-isatty v0.0.12 // indirect
    gitlab.com/silentdata/identity-contract v0.1.2
    golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d // indirect
    golang.org/x/net v0.0.0-20200226121028-0de0cce0169b // indirect
    golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae // indirect
    google.golang.org/grpc v1.27.1 // indirect
)

What am I doing wrong?

Thanks

I think you need to use proto.Registration and proto.Identity? It’s been a while since I touched any Go code :slight_smile:

Hi @softshipper, As @flexd mentioned, did you try to call proto.Identity or proto.Registration? what is the result when you build?

1 Like

There is a short documentation about importing a package and using it. I believe it will help you to understand packages better.

Import declarations

@flexd has already given you the correct answer. Another solution is using . declaration and accessing exported indentifiers without a package qualifier.

import . "gitlab.com/silentdata/identity-contract/proto"

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.