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

* Fix linting errors Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * feat(linters): add ineffassign linter This commit adds the `ineffassign` linter to the project's `.golangci.yml` configuration file. The `ineffassign` linter helps identify and flag assignments to variables that are never used, helping to improve code quality and maintainability. Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * Add extra linters Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * feat(golangci): Add header check - Added goheader check to ensure all files have license headers - Added build tags for "nats" in the .golangci.yml file to include the necessary dependencies for the "nats" package during the build process. - Also, increased the maximum number of issues per linter and the maximum number of same issues reported by the linter to improve the code quality analysis. Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * feat(.golangci.yml): Add new linters Add the following new linters to the .golangci.yml configuration file: - asasalint - asciicheck - bidichk - contextcheck - decorder - dogsled - errchkjson - errname - execinquery - exportloopref - ginkgolinter - gocheckcompilerdirectives These linters will help improve code quality and catch potential issues during the code review process. Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> --------- Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com>
297 lines
5.4 KiB
Go
297 lines
5.4 KiB
Go
// Copyright (c) Mainflux
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package http
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/mainflux/mainflux"
|
|
mfclients "github.com/mainflux/mainflux/pkg/clients"
|
|
)
|
|
|
|
var (
|
|
_ mainflux.Response = (*viewClientRes)(nil)
|
|
_ mainflux.Response = (*createClientRes)(nil)
|
|
_ mainflux.Response = (*deleteClientRes)(nil)
|
|
_ mainflux.Response = (*clientsPageRes)(nil)
|
|
_ mainflux.Response = (*viewMembersRes)(nil)
|
|
_ mainflux.Response = (*memberPageRes)(nil)
|
|
_ mainflux.Response = (*assignUsersGroupsRes)(nil)
|
|
_ mainflux.Response = (*unassignUsersGroupsRes)(nil)
|
|
_ mainflux.Response = (*connectChannelThingRes)(nil)
|
|
_ mainflux.Response = (*disconnectChannelThingRes)(nil)
|
|
)
|
|
|
|
type pageRes struct {
|
|
Limit uint64 `json:"limit,omitempty"`
|
|
Offset uint64 `json:"offset,omitempty"`
|
|
Total uint64 `json:"total,omitempty"`
|
|
}
|
|
|
|
type createClientRes struct {
|
|
mfclients.Client
|
|
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("/things/%s", res.ID),
|
|
}
|
|
}
|
|
|
|
return map[string]string{}
|
|
}
|
|
|
|
func (res createClientRes) Empty() bool {
|
|
return false
|
|
}
|
|
|
|
type updateClientRes struct {
|
|
mfclients.Client
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
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:"things"`
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
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 memberPageRes struct {
|
|
pageRes
|
|
Members []viewMembersRes `json:"things"`
|
|
}
|
|
|
|
func (res memberPageRes) Code() int {
|
|
return http.StatusOK
|
|
}
|
|
|
|
func (res memberPageRes) Headers() map[string]string {
|
|
return map[string]string{}
|
|
}
|
|
|
|
func (res memberPageRes) Empty() bool {
|
|
return false
|
|
}
|
|
|
|
type deleteClientRes struct {
|
|
mfclients.Client
|
|
}
|
|
|
|
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 assignUsersGroupsRes struct{}
|
|
|
|
func (res assignUsersGroupsRes) Code() int {
|
|
return http.StatusOK
|
|
}
|
|
|
|
func (res assignUsersGroupsRes) Headers() map[string]string {
|
|
return map[string]string{}
|
|
}
|
|
|
|
func (res assignUsersGroupsRes) Empty() bool {
|
|
return true
|
|
}
|
|
|
|
type unassignUsersGroupsRes struct{}
|
|
|
|
func (res unassignUsersGroupsRes) Code() int {
|
|
return http.StatusNoContent
|
|
}
|
|
|
|
func (res unassignUsersGroupsRes) Headers() map[string]string {
|
|
return map[string]string{}
|
|
}
|
|
|
|
func (res unassignUsersGroupsRes) Empty() bool {
|
|
return true
|
|
}
|
|
|
|
type assignUsersRes struct{}
|
|
|
|
func (res assignUsersRes) Code() int {
|
|
return http.StatusOK
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
type assignUserGroupsRes struct{}
|
|
|
|
func (res assignUserGroupsRes) Code() int {
|
|
return http.StatusOK
|
|
}
|
|
|
|
func (res assignUserGroupsRes) Headers() map[string]string {
|
|
return map[string]string{}
|
|
}
|
|
|
|
func (res assignUserGroupsRes) Empty() bool {
|
|
return true
|
|
}
|
|
|
|
type unassignUserGroupsRes struct{}
|
|
|
|
func (res unassignUserGroupsRes) Code() int {
|
|
return http.StatusNoContent
|
|
}
|
|
|
|
func (res unassignUserGroupsRes) Headers() map[string]string {
|
|
return map[string]string{}
|
|
}
|
|
|
|
func (res unassignUserGroupsRes) Empty() bool {
|
|
return true
|
|
}
|
|
|
|
type connectChannelThingRes struct{}
|
|
|
|
func (res connectChannelThingRes) Code() int {
|
|
return http.StatusOK
|
|
}
|
|
|
|
func (res connectChannelThingRes) Headers() map[string]string {
|
|
return map[string]string{}
|
|
}
|
|
|
|
func (res connectChannelThingRes) Empty() bool {
|
|
return true
|
|
}
|
|
|
|
type disconnectChannelThingRes struct{}
|
|
|
|
func (res disconnectChannelThingRes) Code() int {
|
|
return http.StatusNoContent
|
|
}
|
|
|
|
func (res disconnectChannelThingRes) Headers() map[string]string {
|
|
return map[string]string{}
|
|
}
|
|
|
|
func (res disconnectChannelThingRes) Empty() bool {
|
|
return true
|
|
}
|
|
|
|
type thingShareRes struct{}
|
|
|
|
func (res thingShareRes) Code() int {
|
|
return http.StatusOK
|
|
}
|
|
|
|
func (res thingShareRes) Headers() map[string]string {
|
|
return map[string]string{}
|
|
}
|
|
|
|
func (res thingShareRes) Empty() bool {
|
|
return true
|
|
}
|
|
|
|
type thingUnshareRes struct{}
|
|
|
|
func (res thingUnshareRes) Code() int {
|
|
return http.StatusNoContent
|
|
}
|
|
|
|
func (res thingUnshareRes) Headers() map[string]string {
|
|
return map[string]string{}
|
|
}
|
|
|
|
func (res thingUnshareRes) Empty() bool {
|
|
return true
|
|
}
|