How to convert a pseudo version of a Golang module into a git commit?

王林
Release: 2024-02-08 23:00:22
forward
1151 people have browsed it

如何将 Golang 模块的伪版本转换为 git 提交?

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.

Question content

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.

Solution

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!

Related labels:
source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!