-2

I have a project with the following structure:

myapp/
  -services/
     -services/
         -exch.go
     -services.go
  -server.go

Having $GOPATH set to /home/dev/dev/go this is how server.go names it's package and imports:

//server.go
package main

import (
  "net/http"
  "github.com/labstack/echo"
  "myapp/services"
)

this is services.go:

//services.go
package services

import (
  "fmt"
  "myapp/services/exch"
)

and this is exch.go:

//exch.go
package exch

import (
  "net/http"
  "fmt"
  "io/ioutil"
  "encoding/json
)

Now, server.go imports package services fine, but services.go cannot find package exch. I tried changing the imports path several ways but cannot make it work. Am I missing something?

Might be useful to know that /myapp is located here: /home/dev/dev/go/src

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
ntonnelier
  • 1,539
  • 3
  • 23
  • 49
  • 1
    One directory per package, one package per directory. If `exch.go` is supposed to be in package `services/exch`, it needs to be in a directory `services/exch`, not in directory `services/services`. – Adrian Jan 08 '19 at 16:50
  • that was it @Adrian. Thanks. If you want to add it as an answer i mark it as accepted. – ntonnelier Jan 08 '19 at 17:02

1 Answers1

0

One directory per package, one package per directory. If exch.go is supposed to be imported as services/exch, it needs to be in a directory services/exch, not in directory services/services.

Adrian
  • 42,911
  • 6
  • 107
  • 99