Posts

Showing posts with the label go

Setting `GOPATH` for each vscode project

Setting `GOPATH` for each vscode project Setting the GOPATH variable global as an enviroment variable works fine with Visual Studio Code. GOPATH But setting a project specific variable globally doesn't seem very nice to me. Consider you have multiple Go projects, you would have to change this variable each time you, compile, debug, ... etc. a project. Go Is there a possibility to set the GOPATH variable as a project variable in Visual Studio Code? Ether in settings.json or launch.json ? GOPATH settings.json launch.json don't try to change GOPATH for each project, use vendor folder – n00dl3 Nov 21 '16 at 8:56 GOPATH vendor 4 Answers 4 Go 1.5 added the vendor directory that allows a per-project dependency management. If there is a source ...

How to get a JSON unique field's name and deeply nested child field's value in Golang?

How to get a JSON unique field's name and deeply nested child field's value in Golang? I have a json file that looks like this { "links": { "uniqueurl_1": { "a": { "b": [ "stuff" ], "I": { "want": { "to": "morestuff", "go": { "in": { "here": { "and": "array", "itis": { "very": "string", "deep": "stringIwant" } } } } } } } } } } And I want to get the uniqueurl_1 (that is always different for each link), and I also want to get the "deep" field's value ("stringIwant") uniqueurl_1 I know if it's ...

TCP Server failing after first response

TCP Server failing after first response NOTE I rewrote this question for the bounty as i was able to figure out how to get the first question solved but didn't want to start a new question. the comments below pertain to the original question, not the revised. Description of Issue My tcp client executes querying the tcp server one time successfully, returns the response, and then subsequent requests to the server from the client fails. Also, if i terminate the client and reload it fails on the first attempt as well. Here's what my command prompt looks like: root@ubuntuT:/home/jon/gocode/udps# ./udpservtcpclient Text to send: SampleQuery Message from server: SampleResponse Text to send: SampleQuery ((End - No Response)) root@ubuntuT:/home/jon/gocode/udps# ./udpservtcpclient Text to send: SampleQuery ((End - No Response)) What I expect I expect to be able to query the tcp server from the tcp client endlessly, and have the tcp server return a response from the UDP Server every tim...

Go-compiled binary won't run in an alpine docker container on Ubuntu host

Go-compiled binary won't run in an alpine docker container on Ubuntu host Given a binary, compiled with Go using GOOS=linux and GOARCH=amd64 , deployed to a docker container based on alpine:3.3 , the binary will not run if the docker engine host is Ubuntu (15.10): GOOS=linux GOARCH=amd64 docker alpine:3.3 sh: /bin/artisan: not found This same binary (compiled for the same OS and arch) will run just fine if the docker engine host is busybox (which is the base for alpine ) deployed within a VirtualBox VM on Mac OS X. busybox alpine This same binary will also run perfectly fine if the container is based on one of Ubuntu images. Any idea what this binary is missing? This is what I've done to reproduce (successful run in VirtualBox/busybox on OS X not shown): Build (building explicitly with flags even though the arch matches): ➜ artisan git:(master) ✗ GOOS=linux GOARCH=amd64 go build Check it can run on the host: ➜ artisan git:(master) ✗ ./artisan 10:14:04.925 [ERROR] artisan:...

Subscribing MQTT using Goroutine not printing messages

Subscribing MQTT using Goroutine not printing messages I currently have Go code that subscribes to a topic and prints out sensor data. The part that prints out the sensor data is in a Goroutine , however, nothing is printing out currently. This is my code: package main import ( "fmt" MQTT "github.com/eclipse/paho.mqtt.golang" "os" "os/signal" "syscall" "sync" ) var wg sync.WaitGroup func subscriber(client MQTT.Client, message MQTT.Message) { wg.Add(1) go func() { defer wg.Done() fmt.Printf("%sn", message.Payload()) }() } func main() { c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt, syscall.SIGTERM) opts := MQTT.NewClientOptions().AddBroker("tcp://test.mosquitto.org:1883") //opts.SetDefaultPublishHandler(f) // Topic to subscribe to for sensor data topic := "sensor/data" client := MQTT.NewClient(opts) if ...