1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-04-29 13:49:28 +08:00
Mainflux.mainflux/http/adapter.go
b1ackd0t ada5813f47
MF-1455 - Update Versions of Protobuf (#1704)
* initial commit
* add protoc-gen-gofast
* update generated files
* fix linting
* fix consumers error on message conversion
* fix copying values on transformers
* initial commit
* initial commit
* add protoc-gen-gofast
* update generated files
* fix linting
* fix consumers error on message conversion
* fix copying values on transformers
* embedded for forward compatible.
* remove gogo
* embedded for forward compatible.
* update protoc compiler
* fix linting
* remove hex comment

Signed-off-by: rodneyosodo <socials@rodneyosodo.com>
2023-02-02 18:28:32 +01: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/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)
}