Skip to content

Commit

Permalink
rename variables for header prefix
Browse files Browse the repository at this point in the history
Signed-off-by: mteodor <[email protected]>
  • Loading branch information
mteodor committed Feb 9, 2022
1 parent 50dad70 commit 6a6b930
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions readers/api/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,25 @@ import (
)

const (
contentType = "application/json"
offsetKey = "offset"
limitKey = "limit"
formatKey = "format"
subtopicKey = "subtopic"
publisherKey = "publisher"
protocolKey = "protocol"
nameKey = "name"
valueKey = "v"
stringValueKey = "vs"
dataValueKey = "vd"
comparatorKey = "comparator"
fromKey = "from"
toKey = "to"
defLimit = 10
defOffset = 0
defFormat = "messages"
thingToken = "Thing "
userToken = "Bearer "
contentType = "application/json"
offsetKey = "offset"
limitKey = "limit"
formatKey = "format"
subtopicKey = "subtopic"
publisherKey = "publisher"
protocolKey = "protocol"
nameKey = "name"
valueKey = "v"
stringValueKey = "vs"
dataValueKey = "vd"
comparatorKey = "comparator"
fromKey = "from"
toKey = "to"
defLimit = 10
defOffset = 0
defFormat = "messages"
thingTokenPrefix = "Thing "
userTokenPrefix = "Bearer "
)

var (
Expand Down Expand Up @@ -210,8 +210,8 @@ func encodeError(_ context.Context, err error, w http.ResponseWriter) {

func authorize(ctx context.Context, req listMessagesReq, tc mainflux.ThingsServiceClient, ac mainflux.AuthServiceClient) (err error) {
switch {
case strings.HasPrefix(req.token, userToken):
token := strings.TrimPrefix(req.token, userToken)
case strings.HasPrefix(req.token, userTokenPrefix):
token := strings.TrimPrefix(req.token, userTokenPrefix)
user, err := usersAuth.Identify(ctx, &mainflux.Token{Value: token})
if err != nil {
e, ok := status.FromError(err)
Expand All @@ -229,7 +229,7 @@ func authorize(ctx context.Context, req listMessagesReq, tc mainflux.ThingsServi
}
return nil
default:
token := strings.TrimPrefix(req.token, thingToken)
token := strings.TrimPrefix(req.token, thingTokenPrefix)
if _, err := thingsAuth.CanAccessByKey(ctx, &mainflux.AccessByKeyReq{Token: token, ChanID: req.chanID}); err != nil {
return errors.Wrap(errThingAccess, err)
}
Expand Down

0 comments on commit 6a6b930

Please sign in to comment.