Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit 91b3b0f

Browse files
committed
Fix linter bugs
1 parent 54730cd commit 91b3b0f

10 files changed

+61
-67
lines changed

api/jsonapi.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func (i *jsonAPIHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
137137
username, password, ok := r.BasicAuth()
138138
h := sha256.Sum256([]byte(password))
139139
password = hex.EncodeToString(h[:])
140-
if !ok || username != i.config.Username || strings.ToLower(password) != strings.ToLower(i.config.Password) {
140+
if !ok || username != i.config.Username || !strings.EqualFold(password, i.config.Password) {
141141
w.WriteHeader(http.StatusForbidden)
142142
fmt.Fprint(w, "403 - Forbidden")
143143
return
@@ -2815,7 +2815,7 @@ func (i *jsonAPIHandler) POSTFetchProfiles(w http.ResponseWriter, r *http.Reques
28152815

28162816
pro, err := i.node.FetchProfile(pid, useCache)
28172817
if err != nil {
2818-
respondWithError("Not found")
2818+
respondWithError("not found")
28192819
return
28202820
}
28212821
obj := pb.PeerAndProfileWithID{Id: id, PeerId: pid, Profile: &pro}
@@ -2827,12 +2827,12 @@ func (i *jsonAPIHandler) POSTFetchProfiles(w http.ResponseWriter, r *http.Reques
28272827
}
28282828
respJSON, err := m.MarshalToString(&obj)
28292829
if err != nil {
2830-
respondWithError("Error Marshalling to JSON")
2830+
respondWithError("error Marshalling to JSON")
28312831
return
28322832
}
28332833
b, err := SanitizeProtobuf(respJSON, new(pb.PeerAndProfileWithID))
28342834
if err != nil {
2835-
respondWithError("Error Marshalling to JSON")
2835+
respondWithError("error Marshalling to JSON")
28362836
return
28372837
}
28382838
i.node.Broadcast <- repo.PremarshalledNotifier{b}
@@ -3581,7 +3581,7 @@ func (i *jsonAPIHandler) POSTFetchRatings(w http.ResponseWriter, r *http.Request
35813581
Error string `json:"error"`
35823582
}
35833583
respondWithError := func(errorMsg string) {
3584-
e := ratingError{id, rid, "Not found"}
3584+
e := ratingError{id, rid, errorMsg}
35853585
ret, err := json.MarshalIndent(e, "", " ")
35863586
if err != nil {
35873587
return
@@ -3590,14 +3590,14 @@ func (i *jsonAPIHandler) POSTFetchRatings(w http.ResponseWriter, r *http.Request
35903590
}
35913591
ratingBytes, err := ipfs.Cat(i.node.IpfsNode, rid, time.Minute)
35923592
if err != nil {
3593-
respondWithError("Not Found")
3593+
respondWithError("not Found")
35943594
return
35953595
}
35963596

35973597
rating := new(pb.Rating)
35983598
err = jsonpb.UnmarshalString(string(ratingBytes), rating)
35993599
if err != nil {
3600-
respondWithError("Invalid rating")
3600+
respondWithError("invalid rating")
36013601
return
36023602
}
36033603
valid, err := core.ValidateRating(rating)
@@ -3617,12 +3617,12 @@ func (i *jsonAPIHandler) POSTFetchRatings(w http.ResponseWriter, r *http.Request
36173617
}
36183618
out, err := m.MarshalToString(resp)
36193619
if err != nil {
3620-
respondWithError("Error marshalling rating")
3620+
respondWithError("error marshalling rating")
36213621
return
36223622
}
36233623
b, err := SanitizeProtobuf(out, new(pb.RatingWithID))
36243624
if err != nil {
3625-
respondWithError("Error marshalling rating")
3625+
respondWithError("error marshalling rating")
36263626
return
36273627
}
36283628
i.node.Broadcast <- repo.PremarshalledNotifier{b}

api/sanitize.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ func sanitize(data interface{}) {
5656
switch d := data.(type) {
5757
case map[string]interface{}:
5858
for k, v := range d {
59-
switch v.(type) {
59+
switch tv := v.(type) {
6060
case string:
61-
d[k] = sanitizer.Sanitize(v.(string))
61+
d[k] = sanitizer.Sanitize(tv)
6262
case map[string]interface{}:
63-
sanitize(v)
63+
sanitize(tv)
6464
case []interface{}:
65-
sanitize(v)
65+
sanitize(tv)
6666
case nil:
6767
delete(d, k)
6868
}

api/ws.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func (wsh wsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
125125
username, password, ok := r.BasicAuth()
126126
h := sha256.Sum256([]byte(password))
127127
password = hex.EncodeToString(h[:])
128-
if !ok || username != wsh.username || strings.ToLower(password) != strings.ToLower(wsh.password) {
128+
if !ok || username != wsh.username || !strings.EqualFold(password, wsh.password) {
129129
wsh.logger.Error("refused websocket connection: invalid username and/or password")
130130
w.WriteHeader(http.StatusForbidden)
131131
fmt.Fprint(w, "403 - Forbidden")

cmd/gencerts.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func (x *GenerateCertificates) Execute(args []string) error {
9090
KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature | x509.KeyUsageCertSign,
9191
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
9292
BasicConstraintsValid: true,
93-
IsCA: true,
93+
IsCA: true,
9494
}
9595

9696
// Create certificate

cmd/start.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -605,15 +605,15 @@ func (x *Start) Execute(args []string) error {
605605
MasterPrivateKey: mPrivKey,
606606
Multiwallet: mw,
607607
OfflineMessageFailoverTimeout: 30 * time.Second,
608-
Pubsub: ps,
609-
PushNodes: pushNodes,
610-
RegressionTestEnable: x.Regtest,
611-
RepoPath: repoPath,
612-
RootHash: string(ourIpnsRecord.Value),
613-
TestnetEnable: x.Testnet,
614-
TorDialer: torDialer,
615-
UserAgent: core.USERAGENT,
616-
IPNSQuorumSize: uint(ipnsExtraConfig.DHTQuorumSize),
608+
Pubsub: ps,
609+
PushNodes: pushNodes,
610+
RegressionTestEnable: x.Regtest,
611+
RepoPath: repoPath,
612+
RootHash: string(ourIpnsRecord.Value),
613+
TestnetEnable: x.Testnet,
614+
TorDialer: torDialer,
615+
UserAgent: core.USERAGENT,
616+
IPNSQuorumSize: uint(ipnsExtraConfig.DHTQuorumSize),
617617
}
618618
core.PublishLock.Lock()
619619

core/order.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -1321,11 +1321,11 @@ collectListings:
13211321
inv.Variant = selectedVariant
13221322
for _, o := range listingMap[item.ListingHash].Item.Options {
13231323
for _, checkOpt := range userOptions {
1324-
if strings.ToLower(o.Name) == strings.ToLower(checkOpt.Name) {
1324+
if strings.EqualFold(o.Name, checkOpt.Name) {
13251325
// var validVariant bool
13261326
validVariant := false
13271327
for _, v := range o.Variants {
1328-
if strings.ToLower(v.Name) == strings.ToLower(checkOpt.Value) {
1328+
if strings.EqualFold(v.Name, checkOpt.Value) {
13291329
validVariant = true
13301330
}
13311331
}
@@ -1335,7 +1335,7 @@ collectListings:
13351335
}
13361336
check:
13371337
for i, lopt := range listingOptions {
1338-
if strings.ToLower(checkOpt.Name) == strings.ToLower(lopt) {
1338+
if strings.EqualFold(checkOpt.Name, lopt) {
13391339
listingOptions = append(listingOptions[:i], listingOptions[i+1:]...)
13401340
continue check
13411341
}
@@ -1385,7 +1385,7 @@ collectListings:
13851385
if option.Type != pb.Listing_ShippingOption_LOCAL_PICKUP {
13861386
var service *pb.Listing_ShippingOption_Service
13871387
for _, shippingService := range option.Services {
1388-
if strings.ToLower(shippingService.Name) == strings.ToLower(item.ShippingOption.Service) {
1388+
if strings.EqualFold(shippingService.Name, item.ShippingOption.Service) {
13891389
service = shippingService
13901390
}
13911391
}
@@ -1646,9 +1646,9 @@ func GetSelectedSku(listing *pb.Listing, itemOptions []*pb.Order_Item_Option) (i
16461646
for _, s := range listing.Item.Options {
16471647
optionsLoop:
16481648
for _, o := range itemOptions {
1649-
if strings.ToLower(o.Name) == strings.ToLower(s.Name) {
1649+
if strings.EqualFold(o.Name, s.Name) {
16501650
for i, va := range s.Variants {
1651-
if strings.ToLower(va.Name) == strings.ToLower(o.Value) {
1651+
if strings.EqualFold(va.Name, o.Value) {
16521652
selected = append(selected, i)
16531653
break optionsLoop
16541654
}

repo/currency_definition_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,13 @@ func TestCurrencyDictionaryValid(t *testing.T) {
235235
expectedErrs := map[string]error{
236236
invalidOne.Code.String(): errOne,
237237
invalidTwo.Code.String(): errTwo,
238-
"DIF": repo.ErrDictionaryIndexMismatchedCode,
238+
"DIF": repo.ErrDictionaryIndexMismatchedCode,
239239
}
240240
_, err := repo.NewCurrencyDictionary(map[string]*repo.CurrencyDefinition{
241241
valid.Code.String(): valid,
242242
invalidOne.Code.String(): invalidOne,
243243
invalidTwo.Code.String(): invalidTwo,
244-
"DIF": valid,
244+
"DIF": valid,
245245
})
246246

247247
var mappedErrs map[string]error

repo/migrations/Migration007_test.go

+15-15
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,19 @@ func TestMigration007(t *testing.T) {
6161
}
6262

6363
_, err = db.Exec(dbSetupSql,
64-
caseID, // dispute case id
65-
int(0), // dispute OrderState
66-
0, // dispute read bool
64+
caseID, // dispute case id
65+
int(0), // dispute OrderState
66+
0, // dispute read bool
6767
int(executedAt.Unix()), // dispute timestamp
68-
0, // dispute buyerOpened bool
69-
"claimtext", // dispute claim text
70-
"", // dispute buyerPayoutAddres
71-
"", // dispute vendorPayoutAddres
68+
0, // dispute buyerOpened bool
69+
"claimtext", // dispute claim text
70+
"", // dispute buyerPayoutAddres
71+
"", // dispute vendorPayoutAddres
7272

73-
purchaseID, // purchase order id
74-
"", // purchase contract blob
75-
1, // purchase state
76-
0, // purchase read bool
73+
purchaseID, // purchase order id
74+
"", // purchase contract blob
75+
1, // purchase state
76+
0, // purchase read bool
7777
int(executedAt.Unix()), // purchase timestamp
7878
int(0), // purchase total int
7979
"thumbnailHash", // purchase thumbnail text
@@ -85,10 +85,10 @@ func TestMigration007(t *testing.T) {
8585
"paymentAddress", // purchase paymentAddr text
8686
0, // purchase funded bool
8787

88-
saleID, // sale order id
89-
"", // sale contract blob
90-
1, // sale state
91-
0, // sale read bool
88+
saleID, // sale order id
89+
"", // sale contract blob
90+
1, // sale state
91+
0, // sale read bool
9292
int(executedAt.Unix()), // sale timestamp
9393
int(0), // sale total int
9494
"thumbnailHash", // sale thumbnail text

repo/migrations/Migration008_test.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,18 @@ func TestMigration008(t *testing.T) {
7979
_, err = db.Exec(dbSetupSql,
8080
caseID, // dispute case id
8181
migrations.Migration008_OrderState_PENDING, // order state int
82-
0, // dispute read bool
82+
0, // dispute read bool
8383
int(executedAt.Unix()), // dispute timestamp
84-
0, // dispute buyerOpened bool
85-
"claimtext", // dispute claim text
86-
"", // dispute buyerPayoutAddres
87-
"", // dispute vendorPayoutAddres
88-
0, // lastNotifiedAt unix timestamp
84+
0, // dispute buyerOpened bool
85+
"claimtext", // dispute claim text
86+
"", // dispute buyerPayoutAddres
87+
"", // dispute vendorPayoutAddres
88+
0, // lastNotifiedAt unix timestamp
8989

9090
purchaseID, // purchase order id
9191
"", // purchase contract blob
9292
migrations.Migration008_OrderState_AWAITING_PAYMENT, // order state int
93-
0, // purchase read bool
93+
0, // purchase read bool
9494
int(executedAt.Unix()), // purchase timestamp
9595
int(0), // purchase total int
9696
"thumbnailHash", // purchase thumbnail text
@@ -106,7 +106,7 @@ func TestMigration008(t *testing.T) {
106106
disputedPurchaseID, // purchase order id
107107
disputedPurchaseContractData, // purchase contract blob
108108
migrations.Migration008_OrderState_DISPUTED, // order state int
109-
0, // purchase read bool
109+
0, // purchase read bool
110110
int(executedAt.Unix()), // purchase timestamp
111111
int(0), // purchase total int
112112
"thumbnailHash", // purchase thumbnail text
@@ -122,8 +122,8 @@ func TestMigration008(t *testing.T) {
122122
saleID, // sale order id
123123
"", // sale contract blob
124124
migrations.Migration008_OrderState_AWAITING_PAYMENT, // order state int
125-
0, // purchase read bool
126-
0, // sale read bool
125+
0, // purchase read bool
126+
0, // sale read bool
127127
int(executedAt.Unix()), // sale timestamp
128128
int(0), // sale total int
129129
"thumbnailHash", // sale thumbnail text

schema/manager_test.go

+4-10
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ func TestOpenbazaarSchemaManager_CleanIdentityFromConfig(t *testing.T) {
401401
t.Error(err)
402402
}
403403

404-
loadConfig := func() (map[string]interface{}, error) {
404+
loadConfig := func() map[string]interface{} {
405405
configPath := path.Join(subject.dataPath, "config")
406406
configFile, err := ioutil.ReadFile(configPath)
407407
if err != nil {
@@ -415,15 +415,12 @@ func TestOpenbazaarSchemaManager_CleanIdentityFromConfig(t *testing.T) {
415415
if !ok {
416416
t.Error("invalid config file")
417417
}
418-
return cfg, nil
418+
return cfg
419419
}
420420

421421
// First load the config and make sure the identity object is indeed set.
422422

423-
cfg, err := loadConfig()
424-
if err != nil {
425-
t.Error(err)
426-
}
423+
cfg := loadConfig()
427424
_, ok := cfg["Identity"]
428425
if !ok {
429426
t.Error("Identity object does not exist in config but should")
@@ -433,10 +430,7 @@ func TestOpenbazaarSchemaManager_CleanIdentityFromConfig(t *testing.T) {
433430
if err := subject.CleanIdentityFromConfig(); err != nil {
434431
t.Error(err)
435432
}
436-
cfg, err = loadConfig()
437-
if err != nil {
438-
t.Error(err)
439-
}
433+
cfg = loadConfig()
440434
_, ok = cfg["Identity"]
441435
if ok {
442436
t.Error("Identity object was not deleted from config")

0 commit comments

Comments
 (0)