Compare commits

...

2 Commits

Author SHA1 Message Date
dusanb94 436db8877d Fix comments
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
2020-10-14 11:03:39 +02:00
dusanb94 4da66aecbf Use shorten messaging API
Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
2020-10-14 10:41:46 +02:00
4 changed files with 9 additions and 9 deletions
+1 -1
View File
@@ -31,7 +31,7 @@ const (
authQuery = "auth"
)
var channelPartRegExp = regexp.MustCompile(`^channels/([\w\-]+)/messages(/[^?]*)?(\?.*)?$`)
var channelPartRegExp = regexp.MustCompile(`^ch/([\w\-]+)/msg(/[^?]*)?(\?.*)?$`)
var errMalformedSubtopic = errors.New("malformed subtopic")
+3 -3
View File
@@ -34,7 +34,7 @@ var (
errMalformedSubtopic = errors.New("malformed subtopic")
)
var channelPartRegExp = regexp.MustCompile(`^/channels/([\w\-]+)/messages(/[^?]*)?(\?.*)?$`)
var channelPartRegExp = regexp.MustCompile(`^/ch/([\w\-]+)/msg(/[^?]*)?(\?.*)?$`)
// MakeHandler returns a HTTP handler for API endpoints.
func MakeHandler(svc adapter.Service, tracer opentracing.Tracer) http.Handler {
@@ -43,14 +43,14 @@ func MakeHandler(svc adapter.Service, tracer opentracing.Tracer) http.Handler {
}
r := bone.New()
r.Post("/channels/:id/messages", kithttp.NewServer(
r.Post("/ch/:id/msg", kithttp.NewServer(
kitot.TraceServer(tracer, "publish")(sendMessageEndpoint(svc)),
decodeRequest,
encodeResponse,
opts...,
))
r.Post("/channels/:id/messages/*", kithttp.NewServer(
r.Post("/ch/:id/msg/*", kithttp.NewServer(
kitot.TraceServer(tracer, "publish")(sendMessageEndpoint(svc)),
decodeRequest,
encodeResponse,
+2 -2
View File
@@ -12,8 +12,8 @@ import (
)
const (
channels = "channels"
messages = "messages"
channels = "ch"
messages = "msg"
)
// Forwarder specifies MQTT forwarder interface API.
+3 -3
View File
@@ -22,7 +22,7 @@ var _ session.Handler = (*handler)(nil)
const protocol = "mqtt"
var (
channelRegExp = regexp.MustCompile(`^\/?channels\/([\w\-]+)\/messages(\/[^?]*)?(\?.*)?$`)
channelRegExp = regexp.MustCompile(`^\/?ch\/([\w\-]+)\/msg(\/[^?]*)?(\?.*)?$`)
errMalformedTopic = errors.New("malformed topic")
errMalformedData = errors.New("malformed request data")
errMalformedSubtopic = errors.New("malformed subtopic")
@@ -125,7 +125,7 @@ func (h *handler) Publish(c *session.Client, topic *string, payload *[]byte) {
}
h.logger.Info("Publish - client ID " + c.ID + " to the topic: " + *topic)
// Topics are in the format:
// channels/<channel_id>/messages/<subtopic>/.../ct/<content_type>
// ch/<channel_id>/msg/<subtopic>/.../ct/<content_type>
channelParts := channelRegExp.FindStringSubmatch(*topic)
if len(channelParts) < 1 {
@@ -190,7 +190,7 @@ func (h *handler) Disconnect(c *session.Client) {
func (h *handler) authAccess(username string, topic string) error {
// Topics are in the format:
// channels/<channel_id>/messages/<subtopic>/.../ct/<content_type>
// ch/<channel_id>/msg/<subtopic>/.../ct/<content_type>
if !channelRegExp.Match([]byte(topic)) {
h.logger.Info("Malformed topic: " + topic)
return errMalformedTopic