Live data from Hacker News

How to start a Go project in 2018

boyter.org

11–20 of 117 posts

Re: How to start a Go project in 2018

#12
post #7

If you're using Go with Docker 17.05 or higher, I recommend a multi-stage Docker build. Official documentation here: https://docs.docker.com/develop/develop-images/multistage-bu... The default Go Docker images include everything needed to compile Go. But once you have a binary, you really only need an image capable of running your binary. I've seen images sizes reduced by over 95%. Revising the example in the article…

Another option for even smaller images is to use distroless: https://github.com/GoogleContainerTools/distroless#examples-...

Re: How to start a Go project in 2018

#13
post #10

Couple of quick notes from my phone, as a googler gopher: - IIRC package management was historically left to the community to solve for, rather than the go maintainers mandating how package mgmt should be done. Many languages have followed this model. I've never heard of it having to do anything with our mono repo model. The community never ended up standardizing on a model; since then, the go team has endorsed godep…

As the parent mentions, vgo is still very experimental. But if you'd like to try it out (or contribute!), I recommend the following links:

The official Go issue: https://github.com/golang/go/issues/24301

And Russ Cox's Tour of vgo: https://research.swtch.com/vgo-tour

Which is part of Russ Cox's vgo series: https://research.swtch.com/vgo

Re: How to start a Go project in 2018

#14
post #7

If you're using Go with Docker 17.05 or higher, I recommend a multi-stage Docker build. Official documentation here: https://docs.docker.com/develop/develop-images/multistage-bu... The default Go Docker images include everything needed to compile Go. But once you have a binary, you really only need an image capable of running your binary. I've seen images sizes reduced by over 95%. Revising the example in the article…

I've been using `scratch` final builds .-

    FROM golang:1.10
    WORKDIR /go/src/bitbucket.code.company-name.com.au/scm/code
    COPY ./ ./
    RUN CGO_ENABLED=0 go build -a -installsuffix cgo -o /dist/main .

    FROM scratch
    COPY --from=0 /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
    COPY --from=0 /go/src/bitbucket.code.company-name.com.au/scm/code/dist/main /
    ENTRYPOINT ["/main"]
It requires a bit more "magic", but is a smaller build at the end.

Re: How to start a Go project in 2018

#15

It feels like a slight failure that things like this are necessary, especially for a new language. As a Python developer, I am no stranger to slightly ridiculous packaging / environment woes. However Go has 19 years on Python. I understand that they are different languages and ostensibly serve different purposes, but it feels like a shortcoming to me - based on the little Go experience I've had.

> As a Python developer, I am no stranger to slightly ridiculous packaging / environment woes.

Speaking of which, what is the best way to start a python project in 2018, now? Python's version and dependency management is my least favorite aspect of the language.

Re: How to start a Go project in 2018

#17
I'd add:

One you set it up, document exactly that setup in readme. If you use something specific for dep management, document it. If not, document it. Document how to run tests. Document everything...

At work I often run into issues with "random project X on GitHub" and do a bit of drive-by fixes. But many times when I find some Go project, I have no idea how to get from a fresh repo to running tests. And if that requires a lot of time to figure out, you're getting a vague issue that I may not want to spend time on, rather than a ready PR. Unfortunately this happens for go projects much more than other languages in my experience.

Re: How to start a Go project in 2018

#18

Nice summary. The biggest pain with Go is the dependency management. I initially started to commit the whole vendor folder for each project, but lately I only commit the Gopkg.lock and Gopkg.toml Both those approaches bothered me over time and I'm still undecided about what's the best way to do this. I know some projects only commit their Gopkg.toml (and not lock) with some explicit dependencies.

They're in the process of fixing dependency management with "vgo".

Re: How to start a Go project in 2018

#20

It feels like a slight failure that things like this are necessary, especially for a new language. As a Python developer, I am no stranger to slightly ridiculous packaging / environment woes. However Go has 19 years on Python. I understand that they are different languages and ostensibly serve different purposes, but it feels like a shortcoming to me - based on the little Go experience I've had.

> As a Python developer, I am no stranger to slightly ridiculous packaging / environment woes. Speaking of which, what is the best way to start a python project in 2018, now? Python's version and dependency management is my least favorite aspect of the language.

> Speaking of which, what is the best way to start a python project in 2018

Pipenv[1] and flit[2]. Together, these do most of what npm/yarn provide for a Node.js project.

Pipenv for installing packages. It’s a virtual environment manager (like pyenv, virtualenv, venv) that’s aware of and stays in sync with the package requirements list, and supports repeatable builds. It claims to be “officially recommended”, and Travis and Heroku, for example, detect its configuration file.

Flit for publishing a package. It’s driven from a declarative project file.[3]

EDIT: Added details and a link to [3].

[1] http://docs.pipenv.org/

[2] http://flit.readthedocs.io/en/latest/

[3] http://flit.readthedocs.io/en/latest/flit_ini.html

Post reply on HN