Golang Go语言:Armed Golang 💪

发布于 1周前 作者 songsunli 来自 Go语言

Golang Go语言:Armed Golang 💪

Gos: Armed Golang 💪

CircleCI Go Report Card Build Status GoDoc Gitter chat

gos

Project Address: https://github.com/storyicon/gos

The current gos is still an alpha version, welcome more people to comment and improve it 🍓, you can add more commands to it, or modify something to make it perform better.

You can download the compiled binary program here: Release Page

🦄 Brief introduction

from now on, use gos instead of go:

go get => gos get
go build => gos build
go run => gos run
go ... => gos ...

gos is compatible with all go commands and has go mod/get equipped with smart GOPROXY, it automatically distinguishes between private and public repositories and uses GOPROXY to download your lost package when appropriate.

gos has a few extra commands to enhance your development experience:

  cross      agile and fast cross compiling
  proto      quick and easy compilation of proto files

You can use -h on these sub commands to get more information.

🐋 How to start

This can't be simpler.
According to your system type, download the zip file from the release page, unzip, rename the binaries to gos and put it in your $PATH. Then use gos as if you were using the go command.
You can also download the source code and compile it using go build -o gos main.go

Note: The prerequisite for gos to work properly is that the go binary is in your $PATH. If you need to use the gos proto command, you need the protoc binary too.

:tangerine: What GOS can do:

1. Fully compatible with Go native commands

You can use gos just like you would with the go command. Compatible with all flags and arguments, such as the following:

go get -u -v github.com/xxxx/xxxx
=>
gos get -u -v github.com/xxxx/xxxx

2. Simpler Cross-Compilation

You can use gos cross command for simpler cross-compilation:

# Compile Linux platform binaries for the current system architecture
# For example, if your computer are amd64, it will compile main.go into the binary of linux/amd64 architecture.
gos cross main.go linux

Specify the build platform and architecture

gos cross main.go linux amd64 gos cross main.go linux arm gos cross main.go linux 386 gos cross main.go windows amd64 gos cross main.go darwin 386

Compiling binary files for all architectures on the specified platform

gos cross main.go linux all gos cross main.go windows all

Compiling binary files for all platforms on the specified architecture

gos cross main.go all amd64

Trying to compile binary files for all platforms and architectures

gos cross all all

Gos uses parallel compilation, very fast 🚀, but still depends on the configuration of your operating system.

more information: gos cross -h

3. Rapid generation of .proto

This feature may only be useful to RPC developers. You can compile proto files more easily, as follows:

# Compile a single file
gos proto helloworld.proto

Compile all proto files under the current folder (excluding subfolders)

gos proto all

Compile all proto files in the current directory and all subdirectories

gos proto all/all

Of course, the precondition is that you have a protoc binary in your $PATH.

more information: gos proto -h

4. Go proxy solution

There is a dilemma here. If you don't use GOPROXY, there may be a large number of Package pull timeouts (network reasons) or non-existence (repository rename, delete or migrate), like the following:

unrecognized import path "golang.org/x/net" ( https fetch: Get https://golang.org/x/net?go-get=1: 
dial tcp 216.239.37.1:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.)

If use GOPROXY, you will not be able to pull the private repositories (github, gitlab, etc) properly, like that:

go get github.com/your_private_repo: unexpected status ( https://athens.azurefd.net/github.com/your_private_repo/[@v](/user/v)/list): 500 Internal Server Error

GOS strengthens all of GO's native commands, no matter it's go mod/get/build/run/....Any situation that might cause a package pull, gos will intelligently determine whether the current repository to be pulled needs to use GOPROXY.

Now, live your thug life 😎


更多关于Golang Go语言:Armed Golang 💪的实战系列教程也可以访问 https://www.itying.com/category-94-b0.html

18 回复

这个轮子。。。emmmm

更多关于Golang Go语言:Armed Golang 💪的实战系列教程也可以访问 https://www.itying.com/category-94-b0.html


一个 makefile 能搞定的事情,一定要开个项目?

交叉编译支持 cgo 吗?

Transparent proxy is a better way, just try sower with socks5 mode.

此 proxy 非彼 proxy

与原生 GO 行为保持一致

使用场景不同

在使用 GOMODULE 时往往会出现 Internal Server Error 或 Timeout 等问题。
GOPROXY 能够在一定程度上解决在拉取诸如 golang.org/x 包的时候产生的超时问题,也可以在一定程度上解决由于项目改名、迁移、删除等原因导致的 404 问题。
但是需要注意的是,使用 GOPROXY 将导致你无法拉取私有储存库。
GOS 主要解决的是这个问题。

GOPROXY 支持多个地址。

你根本不知道 我要解决的是什么问题,并在此基础上,作出判断

sorry guy , there may be some misunderstanding.

star 一下,交叉编译对我来说很有用,gos 方便多了。不过应该还是不支持 CGO 吧?

很感谢你提到这点,这对我很有用(其实你可以提一个 issue 方便更多人看到它)。我注意到在 golang/go 的 master 分支上确实已经支持了“ GOPROXY 可以设置多个,用逗号分隔”这个特性,很高兴 Golang 对此作出了改进。
我目前开发使用的版本是 1.12.4,在官网 https://golang.google.cn/dl/最新的发布版本是 1.12.5,目前在这两个版本下,经过我的测试,GOPROXY 都还暂时不支持这个特性,如果包含逗号,将会提示 invalid $GOPROXY setting: cannot have comma
在 master 分支的文档显示,只有在 GOPROXY 服务器返回 404 与 410 时,GOPROXY 才会使用逗号后面的下一个代理进行尝试,不幸的是,大多数主流的 GOPROXY (比如中国常用的 goproxy.io 、微软的 athens )在拉取储存库失败时,返回的是 500 Internal Server Error。这意味着,即使 Golang 的最新发行版支持了这个特性,在相当的一段时间里,可能仍然无法通过设置 GOPROXY=https://goproxy-address,direct 这样的方式,来解决在设置 GOPROXY 的情况下无法正常拉取私有储存库的问题。
如果上面内容有误,还请告知,可能几个小时后我将会把这个问题在 GOS 项目中以文档的形式叙述。

Thank you for supporting the development of the open source community 😃

1.13 发布之后,主流 GOPROXY 服务器自然会跟进

Looking forward to that day 😛

在IT领域,Go语言(Golang)凭借其简洁、高效和并发处理能力强大的特点,迅速成为了开发者们的宠儿。对于“Armed Golang 💪”这一表述,可以理解为装备了强大功能的Go语言,它确实不负此名。

Go语言拥有简洁明了的语法,使得开发者能够快速上手并编写出高质量的代码。其内置的并发处理机制,如goroutines和channels,让处理并发任务变得轻松且高效,这在构建高性能服务器和微服务架构时尤为重要。

此外,Go语言还具备出色的跨平台性能,能够在多种操作系统上无缝运行,这对于需要跨平台部署的应用来说无疑是一个巨大的优势。同时,Go语言的编译速度也非常快,这大大缩短了开发周期,提升了开发效率。

在安全性方面,Go语言也表现出色。其内置的内存管理机制和垃圾回收机制,有效避免了内存泄漏和指针错误等常见的安全问题。同时,Go语言的社区也非常活跃,不断推动着语言的改进和发展,这为Go语言的安全性提供了坚实的保障。

因此,“Armed Golang 💪”确实是对Go语言强大功能的生动描述。无论是对于初学者还是经验丰富的开发者来说,Go语言都是一个值得学习和掌握的工具。它不仅能够提升开发效率,还能够为应用提供强大的性能和安全性保障。在未来,随着技术的不断发展,相信Go语言将会在更多领域展现出其独特的魅力。

回到顶部