-3

I'm trying to write a service in go with gRPC, and when i import the protobuff file , getting an error. i tried removing all the modules in my go path and reinitialising the go modules

build _/Users/tibinlukose/cart-service/pb: cannot find module for path _/Users/tibinlukose/cart-service/pb

Code

package main

import (
    pbcart "../pb/"
    "log"
    "fmt"
    "google.golang.org/grpc"
    "net"
)

var (
    port = 1000;
)

type CartServiceServer struct {
}

func main() {
    log.SetFlags(log.LstdFlags | log.Lshortfile)
    fmt.Println("Server Starting ..")
    lis, err := net.Listen("tcp", fmt.Sprintf("localhost:%d", 10000))
    if err != nil {
        log.Fatal("unable to listen on the port")
    }
    serverOptions := []grpc.ServerOption{}
    grpcServer := grpc.NewServer(serverOptions...)
    srv := &CartServiceServer{}
    pbcart.RegisterCartServiceServer(grpcServer, srv)
}

env

GOCACHE="/Users/tibinlukose/Library/Caches/go-build"
GOENV="/Users/tibinlukose/Library/Application Support/go/env"
GOPATH="/Users/tibinlukose/go"
GOROOT="/usr/local/Cellar/go/1.13.4/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.13.4/libexec/pkg/tool/darwin_amd64"
GOMOD="/Users/tibinlukose/cart-service/server/go.mod"

repo https://github.com/zycon/cart-service

Tibin
  • 612
  • 1
  • 8
  • 21

1 Answers1

2

Move your go.mod to the root and update import to github.com/zycon/cart-service/pb?

There is no relative import in Go. You can see this answer for an extended explanation: Relative imports in Go

There is a proposal: https://github.com/golang/go/issues/20883

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
ferhatelmas
  • 3,818
  • 1
  • 21
  • 25
  • Kewl, it woks , could you give some info where i went wrong, @Flimzy mentioned not use relative imports. – Tibin Dec 17 '19 at 10:52