0

I am creating a http server with Golang. (I have a Php dev background.) In the internal/app/model I plan on making several packages with artificial logic and I would wish to load all the sub-directories of the model folder in main.go.

I have following folder structure:

[project folder]
\_cmd
     \_main.go
.
.
.
\_internal
          \_app
               \_model
                      \_article
                      \_product

I have tried something in this sense without success:

import (
    "[project_folder]/[project]/internal/app/model/*"
)
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
  • 1
    That's not possible in Go. If you need all the models all the time they should probably all be in the same package. Don't make tons of tiny packages in Go. – Peter Apr 06 '19 at 07:25

1 Answers1

0

You would either:

  • need to place project_folder in $GOPATH/src (as in here): the old way
  • use a go mod init project_folder in order to declare a module named project_folder: the new way, with go modules. (use set GO111MODULE=on or export GO111MODULE=on)

In the latter case, your project_folder can be anywhere: no more GOPATH.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I think you misunderstood the question. The question is how to do some sort of wildcard import, importing multiple packages at once. – Peter Apr 06 '19 at 07:22
  • @Peter as in with wildcard? There is no wildcard in import, I think (https://stackoverflow.com/a/53356110/6309) – VonC Apr 06 '19 at 07:24