main.go not able to find the package

51 views Asked by At

Actually I want to use c4 to generate the c4 id for the video files, So I found the below repo which is developed to do this thing, So I clone this repo https://github.com/Avalanche-io/c4/tree/v0.7.0

Now as suggested in this answer from stack overflow: Not able to install cmd version of c4 from github

I execute the following command in my ubuntu terminal

go get github.com/Avalanche-io
go get github.com/Avalanche-io/c4/id
go get github.com/Avalanche-io/c4/cmd/c4

then as they have shown in the example of how to use this repo

package main

import (
  "fmt"
  "io"
  "os"

  c4 "github.com/avalanche-io/c4/id"
)

func main() {
  file := "main.go"
  f, err := os.Open(file)
  if err != nil {
    panic(err)
  }
  defer f.Close()

  // create a ID encoder.
  e := c4.NewEncoder()
  // the encoder is an io.Writer
  _, err = io.Copy(e, f)
  if err != nil {
    panic(err)
  }
  // ID will return a *c4.ID.
  // Be sure to be done writing bytes before calling ID()
  id := e.ID()
  // use the *c4.ID String method to get the c4id string
  fmt.Printf("C4id of \"%s\": %s\n", file, id)
  return
}

I just copy this same example and created a main.go file and when I run this command which they have defined here in their README.md https://github.com/Avalanche-io/c4/blob/v0.7.0/id/README.md The command is go run main.go ```` Instead of getting the c4 id``` of the file as they have shown in their example. I am getting the following error

main.go:8:3: cannot find package "github.com/avalanche-io/c4/id" in any of:
    /usr/lib/go-1.13/src/github.com/avalanche-io/c4/id (from $GOROOT)
    /home/vinay/go/src/github.com/avalanche-io/c4/id (from $GOPATH)

I don't know about go language so it is becoming very difficult for me to solve the problem here, Is there any go developer which will help me out.

1

There are 1 answers

1
Vinay Kumar On BEST ANSWER

main.go file is not able to find the package github.com/avalanche-io/c4/id inside /home/vinay/go/src/github.com/avalanche-io/c4/id , As I can see you have run the following go get commands

go get github.com/Avalanche-io
go get github.com/Avalanche-io/c4/id
go get github.com/Avalanche-io/c4/cmd/c4

but none of them has name github.com/avalanche-io/c4/id so according to me, You need to execute the following command

go get github.com/avalanche-io/c4/id

Now just run your main.go

go run main.go