mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-27 13:48:49 +08:00

* Move messaging to pkg Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Move errors to pkg Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Move Transformers to pkg Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Move SDK to pkg Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Remove Transformers from root Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Fix make proto Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Add copyrights header Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Fix CI Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Move Auth client to pkg Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Fix dependencies Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Update dependencies and vendors Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Fix CI Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com>
49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
// Copyright (c) Mainflux
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// Package http contains the domain concept definitions needed to support
|
|
// Mainflux http adapter service functionality.
|
|
package http
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/mainflux/mainflux"
|
|
"github.com/mainflux/mainflux/pkg/messaging"
|
|
)
|
|
|
|
// Service specifies coap service API.
|
|
type Service interface {
|
|
// Publish Messssage
|
|
Publish(ctx context.Context, token string, msg messaging.Message) error
|
|
}
|
|
|
|
var _ Service = (*adapterService)(nil)
|
|
|
|
type adapterService struct {
|
|
publisher messaging.Publisher
|
|
things mainflux.ThingsServiceClient
|
|
}
|
|
|
|
// New instantiates the HTTP adapter implementation.
|
|
func New(publisher messaging.Publisher, things mainflux.ThingsServiceClient) Service {
|
|
return &adapterService{
|
|
publisher: publisher,
|
|
things: things,
|
|
}
|
|
}
|
|
|
|
func (as *adapterService) Publish(ctx context.Context, token string, msg messaging.Message) error {
|
|
ar := &mainflux.AccessByKeyReq{
|
|
Token: token,
|
|
ChanID: msg.Channel,
|
|
}
|
|
thid, err := as.things.CanAccessByKey(ctx, ar)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
msg.Publisher = thid.GetValue()
|
|
|
|
return as.publisher.Publish(msg.Channel, msg)
|
|
}
|