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

* Replace Nats with Nats Jestream For PubSub Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Add Stream Description Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Fix connection leak in NATS publisher The publisher struct in pkg/messaging/nats/publisher.go was modified to include a new `conn` field of type `*broker.Conn`. This change was made to fix a connection leak issue in the NATS publisher. The `NewPublisher` function was updated to assign the `conn` parameter to the new `conn` field in the publisher struct. Additionally, the `Close` method in the publisher struct was modified to close the `conn` connection. This commit fixes the connection leak issue in the NATS publisher and ensures that connections are properly closed. Signed-off-by: Rodney Osodo <socials@rodneyosodo.com> * Setup subscriber config to contain handler topic and ID Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Add delivery policy Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Avoid duplicate messages Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Rename to DeliveryPolicy Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Fix tests Signed-off-by: rodneyosodo <blackd0t@protonmail.com> * Not check for data result set when we are returning subset of messages Signed-off-by: Rodney Osodo <socials@rodneyosodo.com> Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * For unsubscribe remove config Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * Fix comment Signed-off-by: rodneyosodo <blackd0t@protonmail.com> --------- Signed-off-by: rodneyosodo <blackd0t@protonmail.com> Signed-off-by: Rodney Osodo <socials@rodneyosodo.com> Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
215 lines
3.9 KiB
Go
215 lines
3.9 KiB
Go
// Copyright (c) Mainflux
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package api
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/mainflux/mainflux"
|
|
mfclients "github.com/mainflux/mainflux/pkg/clients"
|
|
)
|
|
|
|
// MailSent message response when link is sent.
|
|
const MailSent = "Email with reset link is sent"
|
|
|
|
var (
|
|
_ mainflux.Response = (*tokenRes)(nil)
|
|
_ mainflux.Response = (*viewClientRes)(nil)
|
|
_ mainflux.Response = (*createClientRes)(nil)
|
|
_ mainflux.Response = (*deleteClientRes)(nil)
|
|
_ mainflux.Response = (*clientsPageRes)(nil)
|
|
_ mainflux.Response = (*viewMembersRes)(nil)
|
|
)
|
|
|
|
type pageRes struct {
|
|
Limit uint64 `json:"limit,omitempty"`
|
|
Offset uint64 `json:"offset,omitempty"`
|
|
Total uint64 `json:"total,omitempty"`
|
|
}
|
|
|
|
type createClientRes struct {
|
|
mfclients.Client `json:",inline"`
|
|
created bool
|
|
}
|
|
|
|
func (res createClientRes) Code() int {
|
|
if res.created {
|
|
return http.StatusCreated
|
|
}
|
|
|
|
return http.StatusOK
|
|
}
|
|
|
|
func (res createClientRes) Headers() map[string]string {
|
|
if res.created {
|
|
return map[string]string{
|
|
"Location": fmt.Sprintf("/users/%s", res.ID),
|
|
}
|
|
}
|
|
|
|
return map[string]string{}
|
|
}
|
|
|
|
func (res createClientRes) Empty() bool {
|
|
return false
|
|
}
|
|
|
|
type tokenRes struct {
|
|
AccessToken string `json:"access_token,omitempty"`
|
|
RefreshToken string `json:"refresh_token,omitempty"`
|
|
AccessType string `json:"access_type,omitempty"`
|
|
}
|
|
|
|
func (res tokenRes) Code() int {
|
|
return http.StatusCreated
|
|
}
|
|
|
|
func (res tokenRes) Headers() map[string]string {
|
|
return map[string]string{}
|
|
}
|
|
|
|
func (res tokenRes) Empty() bool {
|
|
return res.AccessToken == "" || res.RefreshToken == ""
|
|
}
|
|
|
|
type updateClientRes struct {
|
|
mfclients.Client `json:",inline"`
|
|
}
|
|
|
|
func (res updateClientRes) Code() int {
|
|
return http.StatusOK
|
|
}
|
|
|
|
func (res updateClientRes) Headers() map[string]string {
|
|
return map[string]string{}
|
|
}
|
|
|
|
func (res updateClientRes) Empty() bool {
|
|
return false
|
|
}
|
|
|
|
type viewClientRes struct {
|
|
mfclients.Client `json:",inline"`
|
|
}
|
|
|
|
func (res viewClientRes) Code() int {
|
|
return http.StatusOK
|
|
}
|
|
|
|
func (res viewClientRes) Headers() map[string]string {
|
|
return map[string]string{}
|
|
}
|
|
|
|
func (res viewClientRes) Empty() bool {
|
|
return false
|
|
}
|
|
|
|
type clientsPageRes struct {
|
|
pageRes
|
|
Clients []viewClientRes `json:"users"`
|
|
}
|
|
|
|
func (res clientsPageRes) Code() int {
|
|
return http.StatusOK
|
|
}
|
|
|
|
func (res clientsPageRes) Headers() map[string]string {
|
|
return map[string]string{}
|
|
}
|
|
|
|
func (res clientsPageRes) Empty() bool {
|
|
return false
|
|
}
|
|
|
|
type viewMembersRes struct {
|
|
mfclients.Client `json:",inline"`
|
|
}
|
|
|
|
func (res viewMembersRes) Code() int {
|
|
return http.StatusOK
|
|
}
|
|
|
|
func (res viewMembersRes) Headers() map[string]string {
|
|
return map[string]string{}
|
|
}
|
|
|
|
func (res viewMembersRes) Empty() bool {
|
|
return false
|
|
}
|
|
|
|
type deleteClientRes struct {
|
|
mfclients.Client `json:",inline"`
|
|
}
|
|
|
|
func (res deleteClientRes) Code() int {
|
|
return http.StatusOK
|
|
}
|
|
|
|
func (res deleteClientRes) Headers() map[string]string {
|
|
return map[string]string{}
|
|
}
|
|
|
|
func (res deleteClientRes) Empty() bool {
|
|
return false
|
|
}
|
|
|
|
type passwResetReqRes struct {
|
|
Msg string `json:"msg"`
|
|
}
|
|
|
|
func (res passwResetReqRes) Code() int {
|
|
return http.StatusCreated
|
|
}
|
|
|
|
func (res passwResetReqRes) Headers() map[string]string {
|
|
return map[string]string{}
|
|
}
|
|
|
|
func (res passwResetReqRes) Empty() bool {
|
|
return false
|
|
}
|
|
|
|
type passwChangeRes struct{}
|
|
|
|
func (res passwChangeRes) Code() int {
|
|
return http.StatusCreated
|
|
}
|
|
|
|
func (res passwChangeRes) Headers() map[string]string {
|
|
return map[string]string{}
|
|
}
|
|
|
|
func (res passwChangeRes) Empty() bool {
|
|
return false
|
|
}
|
|
|
|
type assignUsersRes struct{}
|
|
|
|
func (res assignUsersRes) Code() int {
|
|
return http.StatusCreated
|
|
}
|
|
|
|
func (res assignUsersRes) Headers() map[string]string {
|
|
return map[string]string{}
|
|
}
|
|
|
|
func (res assignUsersRes) Empty() bool {
|
|
return true
|
|
}
|
|
|
|
type unassignUsersRes struct{}
|
|
|
|
func (res unassignUsersRes) Code() int {
|
|
return http.StatusNoContent
|
|
}
|
|
|
|
func (res unassignUsersRes) Headers() map[string]string {
|
|
return map[string]string{}
|
|
}
|
|
|
|
func (res unassignUsersRes) Empty() bool {
|
|
return true
|
|
}
|