导入包装和类型

Here is my problem and my project structure

src
|-->config
       |--> config.go
|-->otherPackage
       |--> otherFile.go
|-->main.go

I have a type on config.go that I would like to use in otherFile.go

But when I tried to add it to the import here theses issues:

  1. imported and not used.
  2. undefined: Config

Although I use it in the function declaration

function(target float64, entries [2]float64, config Config)

What is the problem with this?

I tried to import it with

import (
    "fmt"
    "math"
    "../config"
)

You cannot "import from a package". All you can do is "import the whole package". That means if you import "full/import/path/of/foo" and that package declared itself to be called foo via package foo at the beginning, then everything in this package has to be qualified by foo:

foo.Config

If you package is called config than declaring a variable config will shaddow the whole package: so you have to:

  1. Rename the config variable to e.g. cfg
  2. Reference Config from package config with its qualified name config.Config