How to use “internal” packages?

前端 未结 4 1306
时光说笑
时光说笑 2020-12-09 07:50

I try understand how to organize go code using \"internal\" packages. Let me show what the structure I have:

project/
  internal/
    foo/
      foo.go # pac         


        
4条回答
  •  执笔经年
    2020-12-09 08:41

    below way is more scalable, especially when you plan to build multiple binaries

    github.com/servi-io/api
    ├── cmd/
    │   ├── servi/
    │   │   ├── cmdupdate/
    │   │   ├── cmdquery/
    │   │   └── main.go
    │   └── servid/
    │       ├── routes/
    │       │   └── handlers/
    │       ├── tests/
    │       └── main.go
    ├── internal/
    │   ├── attachments/
    │   ├── locations/
    │   ├── orders/
    │   │   ├── customers/
    │   │   ├── items/
    │   │   ├── tags/
    │   │   └── orders.go
    │   ├── registrations/
    │   └── platform/
    │       ├── crypto/
    │       ├── mongo/
    │       └── json/
    

    The folders inside cmd/ represents the number of binaries you want to build.

    for more

提交回复
热议问题