内部整理包含许多文件的golang软件包

内部整理包含许多文件的golang软件包

本文介绍了内部整理包含许多文件的golang软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Go图书馆,我想分发.它有62个源文件,但我想将API放在一个包中. 有没有一种方法可以在一个包中使用多个目录存储代码?这不是一个庞大的源代码,因为源文件本身很小,如果可能,我想保持这种方式使其可导航.

I've got a Go library that I'd like to distribute. It's got 62 source files, but I'd like to keep the API in a single package. Is there a way I can use multiple directories for code in a single package? It's not a huge amount of source, as the source files themselves are small, and I'd like to keep it that way if possible to make it navigable.

由于它是根据其他语言的相似库建模而成的,因此它目前有两个软件包:/project和/project/models.在学习了更多关于Go打包的知识之后,我现在意识到,这对于分发和使用是不方便的.用户希望使用单个包装.

Since it was modeled after similar libraries in other languages, It's currently got two packages: /project and /project/models. After learning more about Go packaging I now realize that this is unwieldy for distribution and use. The user would prefer a single package.

是否有一种通用"的方式?

Is there a "gopheric" way of doing this?

推荐答案

阅读这两篇文章,以更好地了解最佳做法:

Read this two articles to have a good understanding of the best practices:

  1. 投入生产
  2. 组织Go代码
  1. Go In Production
  2. Organizing Go code

每个路径目录可以是您应用中的单独模块/软件包:

Each path directory can be a separate module/package in your app:

github.com/myaccount/myapp/
    README.md
    Makefile
    applib/
        cmd/
            main.go
            main_test.go
            handlers.go
            handlers_test.go
        lib1/
            main.go
            main_test.go
            process.go
            process_test.go
        lib2/
            foo.go
            foo_test.go
            bar.go
            bar_test.go

这篇关于内部整理包含许多文件的golang软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 23:50