mirror of
https://github.com/mainflux/mainflux.git
synced 2025-05-01 13:48:56 +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>
61 lines
1.0 KiB
Go
61 lines
1.0 KiB
Go
// Copyright (c) Mainflux
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package clients
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
|
|
"github.com/mainflux/mainflux/internal/apiutil"
|
|
)
|
|
|
|
// Role represents Client role.
|
|
type Role uint8
|
|
|
|
// Possible Client role values.
|
|
const (
|
|
UserRole Role = iota
|
|
AdminRole
|
|
)
|
|
|
|
// String representation of the possible role values.
|
|
const (
|
|
Admin = "admin"
|
|
User = "user"
|
|
)
|
|
|
|
// String converts client role to string literal.
|
|
func (cs Role) String() string {
|
|
switch cs {
|
|
case AdminRole:
|
|
return Admin
|
|
case UserRole:
|
|
return User
|
|
default:
|
|
return Unknown
|
|
}
|
|
}
|
|
|
|
// ToRole converts string value to a valid Client role.
|
|
func ToRole(status string) (Role, error) {
|
|
switch status {
|
|
case "", User:
|
|
return UserRole, nil
|
|
case Admin:
|
|
return AdminRole, nil
|
|
}
|
|
return Role(0), apiutil.ErrInvalidRole
|
|
}
|
|
|
|
func (r Role) MarshalJSON() ([]byte, error) {
|
|
return json.Marshal(r.String())
|
|
}
|
|
|
|
func (r *Role) UnmarshalJSON(data []byte) error {
|
|
str := strings.Trim(string(data), "\"")
|
|
val, err := ToRole(str)
|
|
*r = val
|
|
return err
|
|
}
|