What’s the proper way to “go get” a private repository?

You have one thing to configure. The example is based on GitHub but this shouldn’t change the process: $ git config –global url.git@github.com:.insteadOf https://github.com/ $ cat ~/.gitconfig [url “git@github.com:”] insteadOf = https://github.com/ $ go get github.com/private/repo For Go modules to work (with Go 1.11 or newer), you’ll also need to set the GOPRIVATE variable, to … Read more

Organizing a multiple-file Go project [closed]

I would recommend reviewing this page on How to Write Go Code It documents both how to structure your project in a go build friendly way, and also how to write tests. Tests do not need to be a cmd using the main package. They can simply be TestX named functions as part of each … Read more

How to `go test` all tests in my project?

This should run all tests in current directory and all of its subdirectories: $ go test ./… This should run all tests for given specific directories: $ go test ./tests/… ./unit-tests/… ./my-packages/… This should run all tests with import path prefixed with foo/: $ go test foo/… This should run all tests import path prefixed … Read more

Convert byte slice to io.Reader

To get a type that implements io.Reader from a []byte slice, you can use bytes.NewReader in the bytes package: r := bytes.NewReader(byteData) This will return a value of type bytes.Reader which implements the io.Reader (and io.ReadSeeker) interface. Don’t worry about them not being the same “type”. io.Reader is an interface and can be implemented by … Read more

Is it possible to capture a Ctrl+C signal (SIGINT) and run a cleanup function, in a “defer” fashion?

You can use the os/signal package to handle incoming signals. Ctrl+C is SIGINT, so you can use this to trap os.Interrupt. c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt) go func(){ for sig := range c { // sig is a ^C, handle it } }() The manner in which you cause your program to terminate … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)