mirror of
https://github.com/mainflux/mainflux.git
synced 2025-05-02 22:17:10 +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>
81 lines
1.8 KiB
Go
81 lines
1.8 KiB
Go
// Copyright (c) Mainflux
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package clients
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"strings"
|
|
|
|
"github.com/mainflux/mainflux/internal/apiutil"
|
|
)
|
|
|
|
// Status represents Client status.
|
|
type Status uint8
|
|
|
|
// Possible Client status values.
|
|
const (
|
|
// EnabledStatus represents enabled Client.
|
|
EnabledStatus Status = iota
|
|
// DisabledStatus represents disabled Client.
|
|
DisabledStatus
|
|
|
|
// AllStatus is used for querying purposes to list clients irrespective
|
|
// of their status - both enabled and disabled. It is never stored in the
|
|
// database as the actual Client status and should always be the largest
|
|
// value in this enumeration.
|
|
AllStatus
|
|
)
|
|
|
|
// String representation of the possible status values.
|
|
const (
|
|
Disabled = "disabled"
|
|
Enabled = "enabled"
|
|
All = "all"
|
|
Unknown = "unknown"
|
|
)
|
|
|
|
// ErrStatusAlreadyAssigned indicated that the client or group has already been assigned the status.
|
|
var ErrStatusAlreadyAssigned = errors.New("status already assigned")
|
|
|
|
// String converts client/group status to string literal.
|
|
func (s Status) String() string {
|
|
switch s {
|
|
case DisabledStatus:
|
|
return Disabled
|
|
case EnabledStatus:
|
|
return Enabled
|
|
case AllStatus:
|
|
return All
|
|
default:
|
|
return Unknown
|
|
}
|
|
}
|
|
|
|
// ToStatus converts string value to a valid Client/Group status.
|
|
func ToStatus(status string) (Status, error) {
|
|
switch status {
|
|
case "", Enabled:
|
|
return EnabledStatus, nil
|
|
case Disabled:
|
|
return DisabledStatus, nil
|
|
case All:
|
|
return AllStatus, nil
|
|
}
|
|
return Status(0), apiutil.ErrInvalidStatus
|
|
}
|
|
|
|
// Custom Marshaller for Client/Groups.
|
|
func (s Status) MarshalJSON() ([]byte, error) {
|
|
return json.Marshal(s.String())
|
|
}
|
|
|
|
// Custom Unmarshaler for Client/Groups.
|
|
func (s *Status) UnmarshalJSON(data []byte) error {
|
|
str := strings.Trim(string(data), "\"")
|
|
val, err := ToStatus(str)
|
|
*s = val
|
|
return err
|
|
}
|