1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-04-29 13:49:28 +08:00
Drasko DRASKOVIC c7054a07f2 Remove comments, clean code
Signed-off-by: Drasko DRASKOVIC <drasko.draskovic@gmail.com>
2017-10-07 19:13:20 +02:00

31 lines
746 B
Go

package adapter
import (
"log"
"net"
"github.com/dereulenspiegel/coap-mux"
"github.com/dustin/go-coap"
)
func notFoundHandler(l *net.UDPConn, a *net.UDPAddr, m *coap.Message) *coap.Message {
log.Printf("Got message in notFoundHandler: path=%q: %#v from %v", m.Path(), m, a)
if m.IsConfirmable() {
return &coap.Message{
Type: coap.Acknowledgement,
Code: coap.NotFound,
}
}
return nil
}
func (ca *CoAPAdapter) COAPServer() *mux.Router {
r := mux.NewRouter()
r.Handle("/channels/{channel_id}/messages", coap.FuncHandler(ca.sendMessage)).Methods(coap.POST)
r.Handle("/channels/{channel_id}/messages", coap.FuncHandler(ca.observeMessage)).Methods(coap.GET)
r.NotFoundHandler = coap.FuncHandler(notFoundHandler)
return r
}