Skip to content

Instantly share code, notes, and snippets.

@kellabyte
Created December 16, 2013 01:57
Show Gist options
  • Select an option

  • Save kellabyte/7981303 to your computer and use it in GitHub Desktop.

Select an option

Save kellabyte/7981303 to your computer and use it in GitHub Desktop.
package main
import (
"github.com/alecthomas/gozmq"
"fmt"
)
type ClientAgent interface {
ListenAndServe()
Close()
}
type clientAgent struct {
zmqContext *gozmq.Context
clientSocket *gozmq.Socket
}
func NewClientAgent() ClientAgent {
self := &clientAgent{}
self.zmqContext, _ = gozmq.NewContext()
return self
}
func (self *clientAgent) ListenAndServe() {
self.clientSocket, _ = self.zmqContext.NewSocket(gozmq.ROUTER)
self.clientSocket.Bind("tcp://*:5555")
items := gozmq.PollItems{
gozmq.PollItem{Socket: self.clientSocket, Events: gozmq.POLLIN},
}
for {
_, err := gozmq.Poll(items, -1)
if err != nil {
break
}
if items[0].REvents & gozmq.POLLIN != 0 {
multiBytes, _ := self.clientSocket.RecvMultipart(0)
fmt.Printf("[SERVER] %v %s\n", multiBytes[0], multiBytes[1])
}
}
}
func (self *clientAgent) Close() {
self.zmqContext.Close()
self.clientSocket.Close()
}
/*
When I try to run this Go application from the plugin I get the error:
/git/go/src/github.com/kellabyte/zmq_test/main.go:6: undefined: NewClientAgent
/git/go/src/github.com/kellabyte/zmq_test/main.go:9: undefined: NewClient
/git/go/src/github.com/kellabyte/zmq_test/main.go:10: undefined: NewClient
/git/go/src/github.com/kellabyte/zmq_test/main.go:11: undefined: NewClient
But if I compile the project it says it builds fine in the plugin. I ran go build and it reported errors.
I fixed the errors and go build now builds this code properly but the errors above still happe in the plugin.
I would love for the plugin just to use go build so that there's not two confusing build systems!
Included is client_agent.go so that you can see the code that complains above does exist.
*/
package main
import "time"
func main() {
agent := NewClientAgent() // Plugin is trying to autocomplete the variable agent as a type that exists in another package
go agent.ListenAndServe()
client1 := NewClient()
client2 := NewClient()
client3 := NewClient()
client1.Connect()
client2.Connect()
client3.Connect()
time.Sleep(time.Second * 5)
}
@dlsniper

Copy link
Copy Markdown

Can you also please post the output of the go env ? Thanks.

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