Home > Article > Backend Development > How to convert a pseudo version of a Golang module into a git commit?
php editor Youzi will share with you how to convert the pseudo version of the Golang module into a git submission method. In Golang's module management, pseudo versions are used to maintain dependencies in modules that have not yet been released. However, when you are ready to publish the module to a git repository, you need to convert these pseudo-versions into concrete git commits. This article will introduce in detail how to implement this process and help you better manage and maintain the dependencies of Golang modules.
I have two git repositories containing go modules, let's call them controller
and api
. controller
imports api
, so the go.mod
file in the controller
repository depends on the api
repository Contained modules.
My problem is that in order to run the code in controller
I need not only the go code from api
but also some static files contained in the repository (generated from the code ). As far as I know, there is no way to package these static files into a go module so that they are automatically imported into my vendor
folder.
My current approach is to try to add the folder containing the static files as a sparsely checked out git submodule. However, in order to keep this submodule in sync with the go source code imported from api
, I would like a small shell script that automatically checks the go.mod
file for api
The commit referenced by the version of the module.
While this may work for released builds, I would also like it to work for unreleased versions that have a <semantic version>-<commit time in the
go.mod file Poke> - Pseudo version of <commit hash prefix>
.
Is there a way to calculate the complete commit hash of this fake version? I'm assuming this is possible to some extent since go modvendor
is able to checkout the correct version, but the only process I can think of is to search for commits that occurred across all branches at a given time and then select those Commit hash prefix matching... This sounds difficult to do in bash.
Any ideas how to solve this problem? The alternative of importing my static files from api
into controller
is also appreciated, this way keeping them in sync with the supplied version of the api
module.
Thanks Volker for providing the correct answer. Using the embed
package is actually very easy and works well.
One drawback of this solution is that it can only embed files in the go package. Since the files I generate are in a top-level folder that doesn't contain any go code, I have to wrap them in a virtual package to embed them.
The above is the detailed content of How to convert a pseudo version of a Golang module into a git commit?. For more information, please follow other related articles on the PHP Chinese website!