Live data from Hacker News

How to start a Go project in 2018

boyter.org

1–10 of 117 posts

Re: How to start a Go project in 2018

#2
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.

Re: How to start a Go project in 2018

#3
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.

Re: How to start a Go project in 2018

#4

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.

I don’t like a lot of Go features but the GOPATH system is really quite good (until you care about pinning versions, when it becomes not worse than Python).

Re: How to start a Go project in 2018

#5
> For Windows it allows you to share the directory between the WSL and Windows

I've avoided changing the GOPATH by using the following set up:

C:/Users//go (Standard windows GOPATH)

Then symlink in WSL:

ln -s /mnt/c/Users//go ~/go

Works pretty well. Then you can install Go on Windows if you need it, otherwise your dev environment is isolated and your Go code remains on Windows if you remove/refresh WSL. Also if you use file history, the code will be backed up this way in your Windows home as well.

Re: How to start a Go project in 2018

#6

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.

> I initially started to commit the whole vendor folder for each project, but lately I only commit the Gopkg.lock and Gopkg.toml

This really bothers me too; I appreciate Go's liberal application of convention over configuration, but I feel like this part of dep is a break from the simplicity afforded by the aforementioned principle. I often appreciate this in other Go tooling (e.g. gofmt), and I would love if they just made everyone do dep one way (I don't care which.)

Re: How to start a Go project in 2018

#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:

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

    FROM alpine:3.7
    RUN apk add --no-cache ca-certificates
    COPY --from=0 /go/src/bitbucket.code.company-name.com.au/scm/code/main .
    CMD ["./main"]
The `CGO_ENABLED=0` and `apk` are oddities of Alpine Linux specifically. The image you choose to run your binary may not need these.

Re: How to start a Go project in 2018

#8

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.

I don’t like a lot of Go features but the GOPATH system is really quite good (until you care about pinning versions, when it becomes not worse than Python).

GOPATH is going away with vgo so it wasn't really good at all as it forced the developer to adopt a specific folder organization. The fact that go maintainers acknowledged this issue is a sign they are ready to move the language forward.

Re: How to start a Go project in 2018

#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 official experimental package manager, whose learnings were used to design vgo. Vgo is very new, and still being iterated on; check it out though!

- vgo removes the need for GOPATH

- There is a one-line installer to set up your env. It's very useful and simplifies a lot of what this blog talks about.

Sorry I don't have links - on phone at airport! All the above should be easily googleable though! :)

Post reply on HN