go-coap
go-coap copied to clipboard
Example server type assertion doesn't work, causes example to not work
In example/obsserver/obsserver.go, line 42-45:
if value, ok := m.Option(coap.Observe).([]uint8); ok &&
len(value) >= 1 && value[0] == 1 {
go periodicTransmitter(l, a, m)
}
The type assertion gives a false for okay and a wrong value. This causes the if-clause to fail, and so the function periodicTransmitter is never called. I changed the code like this to get it to work:
obss := fmt.Sprint(m.Option(coap.Observe))
value, err := strconv.Atoi(obss)
if err != nil {
log.Fatalf("Could not convert observe value to int", err)
}
if value == 1 {
go periodicTransmitter(l, a, m)
}
with imports of fmt
and strconv
.
Hello sir, when i run the file coap_server.go at the time i am getting the following issue coap_server.go:7:2: cannot find package "github.com/dustin/go-coap" in any of: /usr/lib/go-1.7/src/github.com/dustin/go-coap (from $GOROOT) ($GOPATH not set) please help me
@BALAMURUGANS15 It seems you don't have a proper Go development environment (not related to go-coap). Please follow instructions in https://golang.org/doc/code.html first.
@svansteelandt Isn't there a way without formatting to a string and then converting the string to int? That feels too complex.
cannot find package "github.com/dustin/go-coap" in any of: /usr/local/go/src/github.com/dustin/go-coap (from $GOROOT) /go/src/github.com/dustin/go-coap (from $GOPATH)
@BALAMURUGANS15 Try go get -u github.com/dustin/go-coap