Home > Software design >  Go not recognizing local module in different folder
Go not recognizing local module in different folder

Time:12-09

I'm currently going through a Golang Microservices walkthrough. I've attached the structure of the whole project below.Project structure

In the project, the product-api microservice calls upon a GRPC client in the currency microservice as so:

Import statement in github.com/go_novice/gorilla_microservice/currency (below)

import (
  "context"
  "fmt"

  hclog "github.com/hashicorp/go-hclog"
  protos "github.com/go_novice/go_novice/currency/currency_client"
)

Uses interface from currency_client. Generated by GRPC (below in bold)

type ProductsDB struct {
  currency protos.CurrencyClient
  log      hclog.Logger
  rates    map[string]float64
  client   **protos.Currency_SubscribeRatesClient}**

imports from currency client as well (below in bold)

func (p *ProductsDB) handleUpdates() {
  sub, err := **p.currency.SubscribeRates(context.Background())**
  if err != nil {
    p.log.Error("Unable to subscribe for rates", "error", err)
  }

  p.client = sub

  for {
    rr, err := sub.Recv()
    p.log.Info("Recieved updated rate from server", "dest", rr.GetDestination().String())

    if err != nil {
        p.log.Error("Error receiving message", "error", err)
        return
    }

    p.rates[rr.Destination.String()] = rr.Rate
}

}

The file in currency client is generated with GRPC.

Below is the file with imports, package initiation, and interface used in the above code

// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
//  protoc-gen-go v1.27.1
//  protoc        v3.17.3
// source: currency.proto

package currency_client

import (
    context "context"
    grpc "google.golang.org/grpc"
    codes "google.golang.org/grpc/codes"
    status "google.golang.org/grpc/status"
    protoreflect "google.golang.org/protobuf/reflect/protoreflect"
    protoimpl "google.golang.org/protobuf/runtime/protoimpl"
    reflect "reflect"
    sync "sync"
)

    ...

    type Currency_SubscribeRatesClient interface {
        Send(*RateRequest) error
        Recv() (*RateResponse, error)
        grpc.ClientStream
    }

When I run the main.go file in the product-api microservice, I get the error

go: finding module for package github.com/go_novice/gorilla_microservice/currency/currency_client
    github.com/go_novice/gorilla_microservice/product-api imports
            github.com/go_novice/gorilla_microservice/currency/currency_client: module github.com/go_novice/gorilla_microservice/currency@latest found (v0.0.0-20211207090835-fd919955029f), but does not contain package github.com/go_novice/gorilla_microservice/currency/currency_client

First time posting code on stackoverflow. Sorry for the eye gore.

CodePudding user response:

It looks like your main.go file for product-api is not able to import the currency module as you have 2 go.mod file I suppose

  • Related