go-coap icon indicating copy to clipboard operation
go-coap copied to clipboard

Example server type assertion doesn't work, causes example to not work

Open svansteelandt opened this issue 7 years ago • 5 comments

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.

svansteelandt avatar Jan 26 '18 11:01 svansteelandt

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 avatar Mar 02 '18 07:03 BALAMURUGANS15

@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.

dubek avatar Mar 05 '18 07:03 dubek

@svansteelandt Isn't there a way without formatting to a string and then converting the string to int? That feels too complex.

dubek avatar Mar 05 '18 07:03 dubek

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 avatar Mar 06 '18 07:03 BALAMURUGANS15

@BALAMURUGANS15 Try go get -u github.com/dustin/go-coap

dubek avatar Mar 06 '18 10:03 dubek