swagger发布时去除
Jump to Using gorelease below.
跳至下面的使用gorelease 。
I’m neither a lover nor a hater when it comes to Go and its ecosystem. Generally things Go are a bit rudimentary but very open and accessible. You may have to do some work yourself, but you’ll be able to get results.
当谈到Go及其生态系统时,我既不是爱人也不是恨人。 通常,Go有点基本,但是非常开放且易于访问。 您可能需要自己做一些工作,但是您可以获得结果。
There are simple best practices around versioning and releasing software in general, regardless of language or tool:
总体上,关于版本控制和发布软件,有简单的最佳实践,与语言或工具无关:
Use semantic version numbers to indicate versions.
使用语义版本号指示版本。
Make sure the release version number is constantly branded on source and artifacts. 确保发行版本号始终贴在源代码和工件上。Do those two things and you’ve got an orderly, identifiable, reproducible product.
做到这两点,您就会获得有序,可识别,可复制的产品。
So what does Go expect around releases? If you think exactly the minimum best practice, you’d be right :-) For Go, you need to, use semantic version numbers, and tag your source. Do that and your stuff will work properly in the Go module system.
那么Go对发布会有什么期望? 如果您确切地认为是最低的最佳实践,那么您将是正确的:-)对于Go,您需要使用语义版本号,并标记源。 这样做,您的东西就可以在Go模块系统中正常工作。
In Go, the releases mechanism is part of the module system. Let’s look at some basic operations around modules and releases:
在Go中,发布机制是模块系统的一部分。 让我们看看围绕模块和发行版的一些基本操作:
# What releases are associated with the current project?go list -m allgithub.com/nwillc/snipgogithub.com/DATA-DOG/go-sqlmock v1.3.3github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5github.com/atotto/clipboard v0.1.2...# What versions are available for a specific module?go list -m -versions github.com/nwillc/goreleasegithub.com/nwillc/gorelease v0.1.1 v0.1.2 v0.2.0 v0.3.0 v0.4.0# Getting a modulego get github.com/nwillc/gorelease# Getting a module with a specified versiongo get github.com/nwillc/gorelease@v0.4.0Managing modules in you Go is straight forward, read the link above or just look it up. But the minimum would be as follows. First, you’ll kick off the module support. Let’s assume we’ll be keeping this project in GitHub and the repository will be nwillc/demo:
直接管理Go中的模块,请阅读上面的链接或只是查找它。 但是最小值将如下。 首先,您将启动模块支持。 假设我们将这个项目保存在GitHub中,并且存储库将为nwillc / demo :
go mod init github.com/nwillc/demoThat will add the module plumbing to your current project:
这会将模块管道添加到当前项目中:
ls -1 go.*go.modgo.sumWith that in place you can add modules as needed to your project like:
有了它,您可以根据需要向项目添加模块,例如:
go get golang.org/x/mod/semverAnd reference that module as imports in your code.
并在您的代码中引用该模块作为导入。
What do you do?
你是做什么?
Commit all you code 提交所有代码 Set an appropriate git tag, say v0.1.0设置适当的git标签,例如v0.1.0Push the tag and code to github 将标签和代码推送到githubThat’s all it takes. The steps might look like:
这就是全部。 步骤可能如下所示:
# Make sure the current code is all checked ingit commit -am 'Ready for release v0.1.0'# Now tag itgit tag v0.1.0# Push the taggit push origin v0.1.0# Push the code git pushA few boilerplate steps, it does the job, but lacks some elegance. Read on.
只需几个步骤,即可完成工作,但缺乏一些优雅。 继续阅读。
I wanted to simplify the above steps, as well as achieve one additional thing, I wanted a constant available in the code that contained the tag as a string. There are different approaches to the second goal out there, one popular one is employing a the compile time flags -ldflags -X but I wanted it as part of the code because I wanted all standard build methods, which start from the source, to do the right thing.
我想简化上述步骤,并实现另一件事,我想在包含以字符串形式包含标签的代码中使用一个常量。 实现第二个目标有不同的方法,一种流行的方法是使用编译时标志-ldflags -X,但我希望将其作为代码的一部分,因为我想从源头开始使用所有标准的构建方法正确的事情。
To these ends I wrote a Go program, gorelease, to automate the process. I wrote it in Go on the assumption that if you’re working in Go your environment will be set up to run Go.
为此,我编写了一个Go程序gorelease来自动化该过程。 我在Go中编写它的假设是,如果您在Go中工作,则将环境设置为运行Go。
To use gorelease you’ll need a committed repo, and the following in place:
要使用gorelease,您需要一个已提交的回购协议,以及以下内容:
# Get gorelease - only need to do this oncego get github.com/nwillc/gorelease# Indicate the version to release...echo v0.1.0 > .version# Run goreleasegoreleaseThis will generate a version.go file with the version in it, tag the repo, and push the tag and repo.
这将生成一个其中包含版本的version.go文件,标记存储库,然后推送标记和存储库。
To see more about gorelease, head over to github.
要了解有关gorelease的更多信息,请转到github 。
Go’s module versioning takes a sharp left turn at v2.0.0+ into crazy land, either research it or stay below that version number. It’s not addressed yet in gorelease but what support can be added will be soon.
Go的模块版本控制在v2.0.0 +处向左急转,进入疯狂的状态,要么进行研究,要么将其保持在该版本号以下。 gorelease中尚未解决,但是可以添加什么支持将很快。
翻译自: https://levelup.gitconnected.com/go-go-release-3f326921bc71
swagger发布时去除