1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-05-01 13:48:56 +08:00
Mainflux.mainflux/http/adapter.go
Manuel Imperiale 1d78233fe6
MF-1090 - Use named Interfaces args (#1097)
Signed-off-by: Manuel Imperiale <manuel.imperiale@gmail.com>
2020-04-05 13:15:47 +02:00

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/broker"
)
// Service specifies coap service API.
type Service interface {
// Publish Messssage
Publish(ctx context.Context, token string, msg broker.Message) error
}
var _ Service = (*adapterService)(nil)
type adapterService struct {
broker broker.Nats
things mainflux.ThingsServiceClient
}
// New instantiates the HTTP adapter implementation.
func New(broker broker.Nats, things mainflux.ThingsServiceClient) Service {
return &adapterService{
broker: broker,
things: things,
}
}
func (as *adapterService) Publish(ctx context.Context, token string, msg broker.Message) error {
ar := &mainflux.AccessByKeyReq{
Token: token,
ChanID: msg.GetChannel(),
}
thid, err := as.things.CanAccessByKey(ctx, ar)
if err != nil {
return err
}
msg.Publisher = thid.GetValue()
return as.broker.Publish(ctx, token, msg)
}