Posts

Showing posts with the label go

How to download all dependencies with vgo and a given go.mod?

How to download all dependencies with vgo and a given go.mod? I'm working on a go project, using vgo, with a Dockerfile, and I'd like docker to cache the dependencies of the project such that it has two properties: go.mod go.mod Right now, I do: ... RUN go get -u golang.org/x/vgo COPY . /go/src/whatever RUN vgo install ... But if you change a go file, the dockerfile will have to be rebuilt from the COPY layer onwards. COPY What I'd like, in short, is to do: ... RUN go get -u golang.org/x/vgo COPY go.mod /go/src/whatever RUN vgo install_dependencies COPY . /go/src/whatever RUN vgo install ... That way, if I change go.mod , all the dependencies will be downloaded and rebuilt, but otherwise, we can proceed right to building the binary. go.mod I can see a couple of ways to get behavior like this, but all of them have drawbacks: $GOPATH/src/mod vgo mod -vendor vgo mod -vendor go.mod vgo mod -vendor Can you think of a way for me to get behavior like my imaginary vgo install_depe...

Why does my crypt package give me invalid magic prefix error?

Why does my crypt package give me invalid magic prefix error? I have the following code: import "github.com/kless/osutil/user/crypt/sha512_crypt" c := sha512_crypt.New() hash, err := c.Generate(byte("enter-new-password"), byte("$2a$09$f5561d2634fb28a969f2dO8QeQ70f4bjCnF/.GvPpjj.8jgmtzZP2")) if err != nil { panic(err) } And it produced the following error http: panic serving 192.168.0.16:56730: invalid magic prefix Why does this happen and how do I resolve it? 1 Answer 1 Why does this happen and how do I resolve it? You have an invalid magic prefix. github.com/tredoe/osutil/user/crypt/sha512_crypt/sha512_crypt.go if !bytes.HasPrefix(salt, c.Salt.MagicPrefix) { return "", common.ErrSaltPrefix } Read the crypt package code. PHP: crypt — One-way string hashing PHP: password_hash — Creates a password hash Read the PHP documentation. See your earlier questio...

go tutorial select statement

go tutorial select statement I'm working through the examples at tour.golang.org, and I've encountered this code I don't really understand: package main import "fmt" func fibonacci(c, quit chan int) { x, y := 0, 1 for { select { case c <- x: // case: send x to channel c? x, y = y, x+y case <-quit: // case: receive from channel quit? fmt.Println("quit") return } } } func main() { c := make(chan int) quit := make(chan int) go func() { // when does this get called? for i := 0; i < 10; i++ { fmt.Println(<-c) } quit <- 0 }() fibonacci(c, quit) } I understand the basics of how channels work, but what I don't get is how the above select statement works. The explanation on the tutorial says: "The select statement lets a goroutine wait on multiple communication operations. A select blocks until one of its ...

How to implement the presenter in Golang according to the Clean Architecture?

How to implement the presenter in Golang according to the Clean Architecture? Proper software architecture is key to create a project that is maintainable. What proper means is 100% subjective, but lately I like and try to follow Clean Architecture by Robert C. Martin (aka Uncle Bob). Although I really like the theory, it lacks some sort of practical implementation guide for common technical challenges developers may face. One of the things I've been struggling with for example is properly implementing the presenter layer. The presenter is responsible for accepting the "response" from my use case and formatting it in a way that it can be "presented" to my output device (regardless if it is a web or a CLI application). There are multiple approaches for this problem, but they usually fall under one of these categories: Option 1 is more or less the same as what Clean Architecture/Uncle Bob says (in the book and in various posts, see later), Option 2 is rather an al...

Undefined reference to symbol 'gzclose' error when getting library - go

Undefined reference to symbol 'gzclose' error when getting library - go When I try to get one of my libraries on my linux machine with the following command: go get -t github.com/bakape/thumbnailer then I get this error message: -# github.com/bakape/thumbnailer /usr/bin/ld: /usr/bin/ld: /usr/local/lib/libGraphicsMagick.a(magick_libGraphicsMagick_la-blob.o): undefined reference to symbol 'gzclose' //lib/x86_64-linux-gnu/libz.so.1: error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status People who encountered this error said this is a linking error and they fixed it by adding some additional tags in the Makefile. I did this too, but this did not work for me. I tried so many solutions, but nothing seems to work for me. I'm using the following library: https://github.com/bakape/thumbnailer This is the Makefile: clean: rm -f testdata/*_thumb.* The creator mentioned undocumented zlib dependencies. All of them are installed: z...