Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
svansteelandt opened this issue Jan 26, 2018 · 5 comments

Comments

@svansteelandt
Copy link

svansteelandt commented Jan 26, 2018

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.

@BALAMURUGANS15
Copy link

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

@dubek
Copy link
Collaborator

dubek commented Mar 5, 2018

@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
Copy link
Collaborator

dubek commented Mar 5, 2018

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

@BALAMURUGANS15
Copy link

BALAMURUGANS15 commented Mar 6, 2018 via email

@dubek
Copy link
Collaborator

dubek commented Mar 6, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants