V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
storyicon
V2EX  ›  Go 编程语言

Gos: Armed Golang 💪

  •  1
     
  •   storyicon · 2019-05-21 20:56:29 +08:00 · 16672 次点击
    这是一个创建于 2016 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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/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 😎

    17 条回复    2019-05-23 12:53:44 +08:00
    Maboroshii
        1
    Maboroshii  
       2019-05-21 21:28:21 +08:00 via Android
    这个轮子。。。emmmm
    eslizn
        2
    eslizn  
       2019-05-21 21:39:22 +08:00
    一个 makefile 能搞定的事情,一定要开个项目?
    gamexg
        3
    gamexg  
       2019-05-21 23:53:55 +08:00
    交叉编译支持 cgo 吗?
    wweir
        4
    wweir  
       2019-05-22 05:50:49 +08:00 via Android
    Transparent proxy is a better way, just try sower with socks5 mode.
    storyicon
        5
    storyicon  
    OP
       2019-05-22 12:43:31 +08:00
    @wweir 此 proxy 非彼 proxy
    storyicon
        6
    storyicon  
    OP
       2019-05-22 12:43:56 +08:00
    @gamexg 与原生 GO 行为保持一致
    storyicon
        7
    storyicon  
    OP
       2019-05-22 12:44:24 +08:00
    @eslizn 使用场景不同
    storyicon
        8
    storyicon  
    OP
       2019-05-22 12:45:18 +08:00
    @Maboroshii 在使用 GOMODULE 时往往会出现 Internal Server Error 或 Timeout 等问题。
    GOPROXY 能够在一定程度上解决在拉取诸如 golang.org/x 包的时候产生的超时问题,也可以在一定程度上解决由于项目改名、迁移、删除等原因导致的 404 问题。
    但是需要注意的是,使用 GOPROXY 将导致你无法拉取私有储存库。
    GOS 主要解决的是这个问题。
    reus
        9
    reus  
       2019-05-22 15:20:46 +08:00
    @storyicon GOPROXY 支持多个地址。
    wweir
        10
    wweir  
       2019-05-22 17:21:34 +08:00
    @storyicon 你根本不知道 我要解决的是什么问题,并在此基础上,作出判断
    storyicon
        11
    storyicon  
    OP
       2019-05-22 18:59:39 +08:00
    @wweir sorry guy , there may be some misunderstanding.
    praynise
        12
    praynise  
       2019-05-23 07:28:09 +08:00
    star 一下,交叉编译对我来说很有用,gos 方便多了。不过应该还是不支持 CGO 吧?
    storyicon
        13
    storyicon  
    OP
       2019-05-23 11:04:28 +08:00
    @reus 很感谢你提到这点,这对我很有用(其实你可以提一个 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 项目中以文档的形式叙述。
    storyicon
        14
    storyicon  
    OP
       2019-05-23 11:06:37 +08:00
    @praynise Thank you for supporting the development of the open source community 😃
    reus
        15
    reus  
       2019-05-23 11:17:10 +08:00
    @storyicon 1.13 发布之后,主流 GOPROXY 服务器自然会跟进
    storyicon
        16
    storyicon  
    OP
       2019-05-23 12:18:14 +08:00
    @reus Looking forward to that day 😛
    storyicon
        17
    storyicon  
    OP
       2019-05-23 12:53:44 +08:00
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5084 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 01:13 · PVG 09:13 · LAX 17:13 · JFK 20:13
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.