Skip to content

Conversation

@joneshf
Copy link

@joneshf joneshf commented Sep 3, 2018

Here's that stab I took at writing a go version.

You can run the test file with something like ./test.sh 'go run cmd/scrapyard/main.go'. Might need to go get first, I don't really know.

This is basically the first real go program I've written, so I'm sure there's a ton of stuff that could be improved. Mostly just followed gofmt, golint, and whatever else was around. In particular, I've no clue about libraries or structure or anything like that. So, I'm down to change whatever.

I tried to stay true to the spirit of the Ruby implementation, but there are some differences (explained in the first commit). As mentioned before, it's only the fileyard version. But we can add the S3 version as well if this seems like a good way to go.

Lemme know if you want this, don't want it, want changes, or whatever else. Happy to follow up with whatever, but also would be totally fine with ditching it if you'd prefer something else.

joneshf and others added 3 commits September 3, 2018 13:28
With go, we can create static binaries easily.
We can even create cross-plaform binaries easily.
Meaning, we can make using scrapyard really easy:
acquire the binary and run it.

This isn't a direct copy, some changes happened while implementing:
* `store` accepts exactly one `key`.
    We were only using the first key.
    Also, it's unclear what we'd do with the other keys.
* `search` is the only commands that accepts multiple `keys`
    It's the only command that was using multiple keys.
* `junk` no longer accepts `paths`.
    It might be possible to junk individual paths in a tarball.
    That might be the intent of accepting multiple paths.
* `crush` no longer accepts `keys` or `paths`.
    We were crushing the yard no matter what keys or paths were given.
* There's only support for the file-based yard.
    Implementing the S3 stuff seems doable,
    but wanted to take it one step at a time.
    And this was a pretty big step.

The code isn't the best, I don't know go well enough to write nice code.
But, it seems to have the equivalent behavior as the Ruby version.
It should retain the same behavior with no argument.
But we can also say `./test.sh 'go run cmd/scrapyard/main.go'`
and it will run the interpreted go program.
Or, we can build the binary and run that.

Either way, it allows us to test the go version.
@dgtized
Copy link
Owner

dgtized commented Sep 14, 2018

Hmm, not very familiar with go tooling but had some trouble here. go get in the root didn't work at all, but it did if I cded into cmd/scrapyard/main.go then I could run go get. I also didn't have much luck with test.sh

+ go run cmd/scrapyard/main.go -v search -k 'key-#(a_file)' -y scrapyard -p a_dir
cmd/scrapyard/main.go:4:2: cannot find package "github.com/dgtized/scrapyard/internal/fileyard" in any of:
        /usr/lib/go-1.10/src/github.com/dgtized/scrapyard/internal/fileyard (from $GOROOT)
        /home/clgc/gocode/src/github.com/dgtized/scrapyard/internal/fileyard (from $GOPATH)
cmd/scrapyard/main.go:5:2: cannot find package "github.com/dgtized/scrapyard/internal/parser" in any of:
        /usr/lib/go-1.10/src/github.com/dgtized/scrapyard/internal/parser (from $GOROOT)
        /home/clgc/gocode/src/github.com/dgtized/scrapyard/internal/parser (from $GOPATH)

I suspect I'm just not setting GOROOT or GOPATH somehow but not sure?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants