Getting started with third party code


(Rob) #1

First off, I’m a complete newbie when it comes to Go. I’ve got it installed, both on Windows and Linux, and can create a simple Hello World program, which builds and runs fine.

My reason for learning Go, however, is to rewrite a game server I’ve got in PHP-CLI! So I’m looking for sample code to act as a foundation. I’ve found e.g. https://github.com/name5566/leaf (and https://github.com/name5566/leafserver)

I can clone and download the repository, but haven’t a clue as to how to even build it as-is… The few times I’ve got go build or go install to do anything more than an immediate not found type error, it’s referencing github… I’ve tried putting them in various folder structures, “go init mod”, etc, but with no luck.

If I can’t even build the code as-is, I’m not going to get anywhere learning how to write my own stuff on top.

So… Is there a tutorial anywhere on how to actually download and use third-party code? Starting from the very basics, “create this directory structure, run these exact commands.” …

Embarrassed thanks …


(Holloway) #2

Normally, the author of the repository should guide you on what to do. Example: https://github.com/golangci/golangci-lint#install. Do not feel embarrassed about it when it is not available.


When such guidance is not available, your next priority is to seek out the main package within the repository. Example, on the leaf server, there is a main.go inside https://github.com/name5566/leafserver/tree/master/src/server. So on the root directory, you go build against src/server package instead of the root directory.

Keep in mind that both repositories are outdated and are not using go module. So you will need to go get it with GOPATH set. Try:

$ go get -u github.com/name5566/leafserver/tree/master/src/server

OR 

# Note you need to manually resolve all dependencies if you use go build
$ cd $GOPATH/github.com/name5566/leafserver
$ go build -o ./bin ./src/server

Leaf should be the server library since they have a document inside (https://github.com/name5566/leaf/blob/master/TUTORIAL_EN.md). It’s for you to write your own Leaf server.

The repository is open-source (both are Apache 2.0) so you can browse and read the contents.


When you use 3rd party codes there are a few things to consider:

  1. Update & Distributions - how the authors do, control, and deliver
  2. Security - possibility for malware codes injection
  3. Dependencies Reliance - how do you plan to maintain the dependency
  4. Support - if something breaks down, can you get support in timely and how. Is the project abandoned? etc.

(Eric Lindblad) #3

an example on your Linux box of ‘go get’

$ go get -u gonum.org/v1/gonum/...

copy crews.go from this blog Post and run it

the 1st comment on the below topic might have some links of interest

specifically, the therein cited Projects page has a section on games

Golang for Desktop Applications


(Rob) #4

Thanks everyone. After several days of fiddling, I’ve managed to get leafserver compiling as-is using modules outside gopath… . Changes are mostly changing all the import paths from e.g. ‘server/conf’ to the full github.com path. Also added a -replace directive to the go.mod to point at local copy of leaf. Changes all up at github.com/irrelevantdotcom/leafserver (& /leaf)

Now to start on actually writing my own code … :smiley:


(Holloway) #5

Congrats! Great to hear.


Please feel free to select one of the most appropriate answer and “mark as solved” so that other won’t be working on a solved problems. :grin: