brutella / hc

hc is a lightweight framework to develop HomeKit accessories in Go.
Apache License 2.0
1.74k stars 189 forks source link

Added support for go modules (go 1.11+) #130

Closed fernferret closed 5 years ago

fernferret commented 5 years ago

Added Go Module support. This will not harm exisisting users such as those still using $GOPATH or other dependency managers such as go dep.

Using the new go module's "replace" concept is a great way to develop code on other repositories locally without having to push to my own fork or use vendoring. I can simply maintain a fork, point to it locally (in my project's go.mod) by placing the following in my own go.mod:

module github.com/fernferret/my-proj

require (
    ...
    github.com/brutella/hc v0.1.0
    ...
)

replace github.com/brutella/hc v0.1.0 => /home/fernferret/projects/go/hc

but without a go.mod in hc you get the following error:

go: parsing ../hc/go.mod: open /home/fernferret/projects/go/hc/go.mod: no such file or directory
go: error loading module requirements

Also note: https://github.com/golang/go/wiki/Modules#should-i-commit-my-gosum-file-as-well-as-my-gomod-file

Notes on go dep

I realize there is an Open PR for go dep support, but from what I can tell go dep is still an evolving external standard. I don't see a huge reason to not support both (but I also don't use go dep, go modules give me everything I want, so maybe I'm biased)

Notes on the go mod commands to produce this PR (if you'd like to try it out):

$ go version
1.11+
$ cd /path/to/hc
$ unset GOPATH
$ go mod init github.com/brutella/hc
$ go get -v

That's it.

brutella commented 5 years ago

I'm happy to support Go modules since I'm not a big fan of the current vendoring strategy.