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

Commit

Permalink
Merge pull request #1529 from OpenBazaar/update-go-1.11
Browse files Browse the repository at this point in the history
Update project to use golang v1.11
  • Loading branch information
cpacia authored Apr 1, 2019
2 parents 29a8253 + 2958f1c commit 3442425
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ linters:
- goconst
- govet
- megacheck
- goimports
disable:
- goimports
- errcheck
- golint
- prealloc
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
language: go
go:
- "1.10.3"
- "1.11"
sudo: required
services:
- docker
env:
- "PATH=/home/travis/gopath/bin:$PATH"
before_install:
- go get -u github.com/axw/gocov/gocov github.com/mattn/goveralls github.com/tcnksm/ghr
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin v1.10
- curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin v1.15.0
install:
- echo "No external dependencies required. Skipping travis default library dependency setup to use vendors..."
script:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.10
FROM golang:1.11
WORKDIR /go/src/github.com/OpenBazaar/openbazaar-go
COPY . .
RUN go build --ldflags '-extldflags "-static"' -o /opt/openbazaard .
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.10
FROM golang:1.11
VOLUME /var/lib/openbazaar

RUN wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz && \
Expand Down Expand Up @@ -29,7 +29,7 @@ RUN go get -u github.com/gogo/protobuf/proto \
github.com/icrowley/fake \
github.com/derekparker/delve/cmd/dlv

RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin v1.10
RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin v1.15.0

WORKDIR /go/src/github.com/OpenBazaar/openbazaar-go

Expand Down
18 changes: 9 additions & 9 deletions api/jsonapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func (i *jsonAPIHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
username, password, ok := r.BasicAuth()
h := sha256.Sum256([]byte(password))
password = hex.EncodeToString(h[:])
if !ok || username != i.config.Username || strings.ToLower(password) != strings.ToLower(i.config.Password) {
if !ok || username != i.config.Username || !strings.EqualFold(password, i.config.Password) {
w.WriteHeader(http.StatusForbidden)
fmt.Fprint(w, "403 - Forbidden")
return
Expand Down Expand Up @@ -2815,7 +2815,7 @@ func (i *jsonAPIHandler) POSTFetchProfiles(w http.ResponseWriter, r *http.Reques

pro, err := i.node.FetchProfile(pid, useCache)
if err != nil {
respondWithError("Not found")
respondWithError("not found")
return
}
obj := pb.PeerAndProfileWithID{Id: id, PeerId: pid, Profile: &pro}
Expand All @@ -2827,12 +2827,12 @@ func (i *jsonAPIHandler) POSTFetchProfiles(w http.ResponseWriter, r *http.Reques
}
respJSON, err := m.MarshalToString(&obj)
if err != nil {
respondWithError("Error Marshalling to JSON")
respondWithError("error Marshalling to JSON")
return
}
b, err := SanitizeProtobuf(respJSON, new(pb.PeerAndProfileWithID))
if err != nil {
respondWithError("Error Marshalling to JSON")
respondWithError("error Marshalling to JSON")
return
}
i.node.Broadcast <- repo.PremarshalledNotifier{b}
Expand Down Expand Up @@ -3581,7 +3581,7 @@ func (i *jsonAPIHandler) POSTFetchRatings(w http.ResponseWriter, r *http.Request
Error string `json:"error"`
}
respondWithError := func(errorMsg string) {
e := ratingError{id, rid, "Not found"}
e := ratingError{id, rid, errorMsg}
ret, err := json.MarshalIndent(e, "", " ")
if err != nil {
return
Expand All @@ -3590,14 +3590,14 @@ func (i *jsonAPIHandler) POSTFetchRatings(w http.ResponseWriter, r *http.Request
}
ratingBytes, err := ipfs.Cat(i.node.IpfsNode, rid, time.Minute)
if err != nil {
respondWithError("Not Found")
respondWithError("not Found")
return
}

rating := new(pb.Rating)
err = jsonpb.UnmarshalString(string(ratingBytes), rating)
if err != nil {
respondWithError("Invalid rating")
respondWithError("invalid rating")
return
}
valid, err := core.ValidateRating(rating)
Expand All @@ -3617,12 +3617,12 @@ func (i *jsonAPIHandler) POSTFetchRatings(w http.ResponseWriter, r *http.Request
}
out, err := m.MarshalToString(resp)
if err != nil {
respondWithError("Error marshalling rating")
respondWithError("error marshalling rating")
return
}
b, err := SanitizeProtobuf(out, new(pb.RatingWithID))
if err != nil {
respondWithError("Error marshalling rating")
respondWithError("error marshalling rating")
return
}
i.node.Broadcast <- repo.PremarshalledNotifier{b}
Expand Down
8 changes: 4 additions & 4 deletions api/sanitize.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ func sanitize(data interface{}) {
switch d := data.(type) {
case map[string]interface{}:
for k, v := range d {
switch v.(type) {
switch tv := v.(type) {
case string:
d[k] = sanitizer.Sanitize(v.(string))
d[k] = sanitizer.Sanitize(tv)
case map[string]interface{}:
sanitize(v)
sanitize(tv)
case []interface{}:
sanitize(v)
sanitize(tv)
case nil:
delete(d, k)
}
Expand Down
2 changes: 1 addition & 1 deletion api/ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (wsh wsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
username, password, ok := r.BasicAuth()
h := sha256.Sum256([]byte(password))
password = hex.EncodeToString(h[:])
if !ok || username != wsh.username || strings.ToLower(password) != strings.ToLower(wsh.password) {
if !ok || username != wsh.username || !strings.EqualFold(password, wsh.password) {
wsh.logger.Error("refused websocket connection: invalid username and/or password")
w.WriteHeader(http.StatusForbidden)
fmt.Fprint(w, "403 - Forbidden")
Expand Down
3 changes: 1 addition & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
TARGETS=${1:-windows/386,windows/amd64,darwin/amd64,linux/386,linux/amd64,linux/arm}

export CGO_ENABLED=1
docker pull karalabe/xgo-latest
go get github.com/karalabe/xgo
mkdir dist && cd dist/
xgo -go=1.10 --targets=$TARGETS ../
xgo -go=1.11 --targets=$TARGETS ../
chmod +x *
2 changes: 1 addition & 1 deletion cmd/gencerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (x *GenerateCertificates) Execute(args []string) error {
KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature | x509.KeyUsageCertSign,
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
BasicConstraintsValid: true,
IsCA: true,
IsCA: true,
}

// Create certificate
Expand Down
18 changes: 9 additions & 9 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -605,15 +605,15 @@ func (x *Start) Execute(args []string) error {
MasterPrivateKey: mPrivKey,
Multiwallet: mw,
OfflineMessageFailoverTimeout: 30 * time.Second,
Pubsub: ps,
PushNodes: pushNodes,
RegressionTestEnable: x.Regtest,
RepoPath: repoPath,
RootHash: string(ourIpnsRecord.Value),
TestnetEnable: x.Testnet,
TorDialer: torDialer,
UserAgent: core.USERAGENT,
IPNSQuorumSize: uint(ipnsExtraConfig.DHTQuorumSize),
Pubsub: ps,
PushNodes: pushNodes,
RegressionTestEnable: x.Regtest,
RepoPath: repoPath,
RootHash: string(ourIpnsRecord.Value),
TestnetEnable: x.Testnet,
TorDialer: torDialer,
UserAgent: core.USERAGENT,
IPNSQuorumSize: uint(ipnsExtraConfig.DHTQuorumSize),
}
core.PublishLock.Lock()

Expand Down
12 changes: 6 additions & 6 deletions core/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -1321,11 +1321,11 @@ collectListings:
inv.Variant = selectedVariant
for _, o := range listingMap[item.ListingHash].Item.Options {
for _, checkOpt := range userOptions {
if strings.ToLower(o.Name) == strings.ToLower(checkOpt.Name) {
if strings.EqualFold(o.Name, checkOpt.Name) {
// var validVariant bool
validVariant := false
for _, v := range o.Variants {
if strings.ToLower(v.Name) == strings.ToLower(checkOpt.Value) {
if strings.EqualFold(v.Name, checkOpt.Value) {
validVariant = true
}
}
Expand All @@ -1335,7 +1335,7 @@ collectListings:
}
check:
for i, lopt := range listingOptions {
if strings.ToLower(checkOpt.Name) == strings.ToLower(lopt) {
if strings.EqualFold(checkOpt.Name, lopt) {
listingOptions = append(listingOptions[:i], listingOptions[i+1:]...)
continue check
}
Expand Down Expand Up @@ -1385,7 +1385,7 @@ collectListings:
if option.Type != pb.Listing_ShippingOption_LOCAL_PICKUP {
var service *pb.Listing_ShippingOption_Service
for _, shippingService := range option.Services {
if strings.ToLower(shippingService.Name) == strings.ToLower(item.ShippingOption.Service) {
if strings.EqualFold(shippingService.Name, item.ShippingOption.Service) {
service = shippingService
}
}
Expand Down Expand Up @@ -1646,9 +1646,9 @@ func GetSelectedSku(listing *pb.Listing, itemOptions []*pb.Order_Item_Option) (i
for _, s := range listing.Item.Options {
optionsLoop:
for _, o := range itemOptions {
if strings.ToLower(o.Name) == strings.ToLower(s.Name) {
if strings.EqualFold(o.Name, s.Name) {
for i, va := range s.Variants {
if strings.ToLower(va.Name) == strings.ToLower(o.Value) {
if strings.EqualFold(va.Name, o.Value) {
selected = append(selected, i)
break optionsLoop
}
Expand Down
4 changes: 2 additions & 2 deletions repo/currency_definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,13 @@ func TestCurrencyDictionaryValid(t *testing.T) {
expectedErrs := map[string]error{
invalidOne.Code.String(): errOne,
invalidTwo.Code.String(): errTwo,
"DIF": repo.ErrDictionaryIndexMismatchedCode,
"DIF": repo.ErrDictionaryIndexMismatchedCode,
}
_, err := repo.NewCurrencyDictionary(map[string]*repo.CurrencyDefinition{
valid.Code.String(): valid,
invalidOne.Code.String(): invalidOne,
invalidTwo.Code.String(): invalidTwo,
"DIF": valid,
"DIF": valid,
})

var mappedErrs map[string]error
Expand Down
30 changes: 15 additions & 15 deletions repo/migrations/Migration007_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,19 @@ func TestMigration007(t *testing.T) {
}

_, err = db.Exec(dbSetupSql,
caseID, // dispute case id
int(0), // dispute OrderState
0, // dispute read bool
caseID, // dispute case id
int(0), // dispute OrderState
0, // dispute read bool
int(executedAt.Unix()), // dispute timestamp
0, // dispute buyerOpened bool
"claimtext", // dispute claim text
"", // dispute buyerPayoutAddres
"", // dispute vendorPayoutAddres
0, // dispute buyerOpened bool
"claimtext", // dispute claim text
"", // dispute buyerPayoutAddres
"", // dispute vendorPayoutAddres

purchaseID, // purchase order id
"", // purchase contract blob
1, // purchase state
0, // purchase read bool
purchaseID, // purchase order id
"", // purchase contract blob
1, // purchase state
0, // purchase read bool
int(executedAt.Unix()), // purchase timestamp
int(0), // purchase total int
"thumbnailHash", // purchase thumbnail text
Expand All @@ -85,10 +85,10 @@ func TestMigration007(t *testing.T) {
"paymentAddress", // purchase paymentAddr text
0, // purchase funded bool

saleID, // sale order id
"", // sale contract blob
1, // sale state
0, // sale read bool
saleID, // sale order id
"", // sale contract blob
1, // sale state
0, // sale read bool
int(executedAt.Unix()), // sale timestamp
int(0), // sale total int
"thumbnailHash", // sale thumbnail text
Expand Down
20 changes: 10 additions & 10 deletions repo/migrations/Migration008_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,18 @@ func TestMigration008(t *testing.T) {
_, err = db.Exec(dbSetupSql,
caseID, // dispute case id
migrations.Migration008_OrderState_PENDING, // order state int
0, // dispute read bool
0, // dispute read bool
int(executedAt.Unix()), // dispute timestamp
0, // dispute buyerOpened bool
"claimtext", // dispute claim text
"", // dispute buyerPayoutAddres
"", // dispute vendorPayoutAddres
0, // lastNotifiedAt unix timestamp
0, // dispute buyerOpened bool
"claimtext", // dispute claim text
"", // dispute buyerPayoutAddres
"", // dispute vendorPayoutAddres
0, // lastNotifiedAt unix timestamp

purchaseID, // purchase order id
"", // purchase contract blob
migrations.Migration008_OrderState_AWAITING_PAYMENT, // order state int
0, // purchase read bool
0, // purchase read bool
int(executedAt.Unix()), // purchase timestamp
int(0), // purchase total int
"thumbnailHash", // purchase thumbnail text
Expand All @@ -106,7 +106,7 @@ func TestMigration008(t *testing.T) {
disputedPurchaseID, // purchase order id
disputedPurchaseContractData, // purchase contract blob
migrations.Migration008_OrderState_DISPUTED, // order state int
0, // purchase read bool
0, // purchase read bool
int(executedAt.Unix()), // purchase timestamp
int(0), // purchase total int
"thumbnailHash", // purchase thumbnail text
Expand All @@ -122,8 +122,8 @@ func TestMigration008(t *testing.T) {
saleID, // sale order id
"", // sale contract blob
migrations.Migration008_OrderState_AWAITING_PAYMENT, // order state int
0, // purchase read bool
0, // sale read bool
0, // purchase read bool
0, // sale read bool
int(executedAt.Unix()), // sale timestamp
int(0), // sale total int
"thumbnailHash", // sale thumbnail text
Expand Down
14 changes: 4 additions & 10 deletions schema/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ func TestOpenbazaarSchemaManager_CleanIdentityFromConfig(t *testing.T) {
t.Error(err)
}

loadConfig := func() (map[string]interface{}, error) {
loadConfig := func() map[string]interface{} {
configPath := path.Join(subject.dataPath, "config")
configFile, err := ioutil.ReadFile(configPath)
if err != nil {
Expand All @@ -415,15 +415,12 @@ func TestOpenbazaarSchemaManager_CleanIdentityFromConfig(t *testing.T) {
if !ok {
t.Error("invalid config file")
}
return cfg, nil
return cfg
}

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

cfg, err := loadConfig()
if err != nil {
t.Error(err)
}
cfg := loadConfig()
_, ok := cfg["Identity"]
if !ok {
t.Error("Identity object does not exist in config but should")
Expand All @@ -433,10 +430,7 @@ func TestOpenbazaarSchemaManager_CleanIdentityFromConfig(t *testing.T) {
if err := subject.CleanIdentityFromConfig(); err != nil {
t.Error(err)
}
cfg, err = loadConfig()
if err != nil {
t.Error(err)
}
cfg = loadConfig()
_, ok = cfg["Identity"]
if ok {
t.Error("Identity object was not deleted from config")
Expand Down

0 comments on commit 3442425

Please sign in to comment.