在Go中可以创建诸如静态或动态库之类的东西,并从两个项目中删除源代码并放在一个独立的地方吗? [重复]

This question already has an answer here:

I have couple files with same code, one package for example mailer, shared between two projects in Go. In both projects I have copied exactly the same code and it works. Is possible in Go to create something like static or dynamic library, like in c or c++, and remove source from both projects and put on one neutral place ? How to achieve this in Go ?

</div>

You can create a package for each function (like mailer) and place them in a different GOPATH of common libraries.

In each project add this path to the GOPATH (PROJECT_PATH:COMMON_PATH).

Alternatively, if you can share the code, save the package in Github (package src only, without folder struct) and use go get to fetch the package and keep it updated.