Skip to content

Commit

Permalink
Fix golangci-lint issues (prebid#3679)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitris authored Jun 11, 2024
1 parent 2d2bf71 commit 1979036
Show file tree
Hide file tree
Showing 47 changed files with 122 additions and 97 deletions.
1 change: 1 addition & 0 deletions adapters/adgeneration/adgeneration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ func checkBidResponse(t *testing.T, bidderResponse *adapters.BidderResponse, exp
var expectedCrID string = "Dummy_supership.jp"
var extectedDealID string = "test-deal-id"

//nolint: staticcheck // false positive SA5011: possible nil pointer dereference
assert.Equal(t, expectedCurrency, bidderResponse.Currency)
assert.Equal(t, 1, len(bidderResponse.Bids))
assert.Equal(t, expectedID, bidderResponse.Bids[0].Bid.ID)
Expand Down
6 changes: 5 additions & 1 deletion adapters/adtarget/adtarget.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,11 @@ func validateImpressionAndSetExt(imp *openrtb2.Imp) (int, error) {
impExtBuffer, err = json.Marshal(&adtargetImpExt{
Adtarget: impExt,
})

if err != nil {
return 0, &errortypes.BadInput{
Message: fmt.Sprintf("ignoring imp id=%s, error while encoding impExt, err: %s", imp.ID, err),
}
}
if impExt.BidFloor > 0 {
imp.BidFloor = impExt.BidFloor
}
Expand Down
2 changes: 1 addition & 1 deletion adapters/advangelists/advangelists.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (adapter *AdvangelistsAdapter) buildEndpointURL(params *openrtb_ext.ExtImpA

// MakeBids translates advangelists bid response to prebid-server specific format
func (adapter *AdvangelistsAdapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) {
var msg = ""
var msg string
if response.StatusCode == http.StatusNoContent {
return nil, nil
}
Expand Down
3 changes: 3 additions & 0 deletions adapters/algorix/algorix.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ func preProcess(request *openrtb2.BidRequest) {
videoCopy := *request.Imp[i].Video
videoExt := algorixVideoExt{Rewarded: 1}
videoCopy.Ext, err = json.Marshal(&videoExt)
if err != nil {
continue
}
request.Imp[i].Video = &videoCopy
}
}
Expand Down
8 changes: 4 additions & 4 deletions adapters/beintoo/beintoo.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (a *BeintooAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *ada

if len(request.Imp) == 0 {
return nil, []error{&errortypes.BadInput{
Message: fmt.Sprintf("No Imps in Bid Request"),
Message: "No Imps in Bid Request",
}}
}

Expand All @@ -36,7 +36,7 @@ func (a *BeintooAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *ada
data, err := json.Marshal(request)
if err != nil {
return nil, []error{&errortypes.BadInput{
Message: fmt.Sprintf("Error in packaging request to JSON"),
Message: "Error in packaging request to JSON",
}}
}

Expand Down Expand Up @@ -95,7 +95,7 @@ func buildImpBanner(imp *openrtb2.Imp) error {

if imp.Banner == nil {
return &errortypes.BadInput{
Message: fmt.Sprintf("Request needs to include a Banner object"),
Message: "Request needs to include a Banner object",
}
}

Expand All @@ -105,7 +105,7 @@ func buildImpBanner(imp *openrtb2.Imp) error {
if banner.W == nil && banner.H == nil {
if len(banner.Format) == 0 {
return &errortypes.BadInput{
Message: fmt.Sprintf("Need at least one size to build request"),
Message: "Need at least one size to build request",
}
}
format := banner.Format[0]
Expand Down
8 changes: 4 additions & 4 deletions adapters/between/between.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (a *BetweenAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *ada
var errors []error
if len(request.Imp) == 0 {
return nil, []error{&errortypes.BadInput{
Message: fmt.Sprintf("No valid Imps in Bid Request"),
Message: "No valid Imps in Bid Request",
}}
}
ext, errors := preprocess(request)
Expand All @@ -40,7 +40,7 @@ func (a *BetweenAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *ada
data, err := json.Marshal(request)
if err != nil {
return nil, []error{&errortypes.BadInput{
Message: fmt.Sprintf("Error in packaging request to JSON"),
Message: "Error in packaging request to JSON",
}}
}
headers := http.Header{}
Expand Down Expand Up @@ -103,14 +103,14 @@ func (a *BetweenAdapter) buildEndpointURL(e *openrtb_ext.ExtImpBetween) (string,
func buildImpBanner(imp *openrtb2.Imp) error {
if imp.Banner == nil {
return &errortypes.BadInput{
Message: fmt.Sprintf("Request needs to include a Banner object"),
Message: "Request needs to include a Banner object",
}
}
banner := *imp.Banner
if banner.W == nil && banner.H == nil {
if len(banner.Format) == 0 {
return &errortypes.BadInput{
Message: fmt.Sprintf("Need at least one size to build request"),
Message: "Need at least one size to build request",
}
}
format := banner.Format[0]
Expand Down
2 changes: 1 addition & 1 deletion adapters/bluesea/bluesea.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func extraImpExt(imp *openrtb2.Imp) (*openrtb_ext.ExtImpBluesea, error) {
}
if len(blueseaImpExt.PubId) == 0 || len(blueseaImpExt.Token) == 0 {
return nil, &errortypes.BadInput{
Message: fmt.Sprintf("Error in parsing imp.ext.bidder, empty pubid or token"),
Message: "Error in parsing imp.ext.bidder, empty pubid or token",
}
}
return &blueseaImpExt, nil
Expand Down
12 changes: 6 additions & 6 deletions adapters/cadent_aperture_mx/cadentaperturemx.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.E

if len(request.Imp) == 0 {
return nil, []error{&errortypes.BadInput{
Message: fmt.Sprintf("No Imps in Bid Request"),
Message: "No Imps in Bid Request",
}}
}

Expand All @@ -51,7 +51,7 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.E
data, err := json.Marshal(request)
if err != nil {
return nil, []error{&errortypes.BadInput{
Message: fmt.Sprintf("Error in packaging request to JSON"),
Message: "Error in packaging request to JSON",
}}
}

Expand Down Expand Up @@ -117,7 +117,7 @@ func buildImpBanner(imp *openrtb2.Imp) error {

if imp.Banner == nil {
return &errortypes.BadInput{
Message: fmt.Sprintf("Request needs to include a Banner object"),
Message: "Request needs to include a Banner object",
}
}

Expand All @@ -127,7 +127,7 @@ func buildImpBanner(imp *openrtb2.Imp) error {
if banner.W == nil && banner.H == nil {
if len(banner.Format) == 0 {
return &errortypes.BadInput{
Message: fmt.Sprintf("Need at least one size to build request"),
Message: "Need at least one size to build request",
}
}
format := banner.Format[0]
Expand All @@ -144,13 +144,13 @@ func buildImpVideo(imp *openrtb2.Imp) error {

if len(imp.Video.MIMEs) == 0 {
return &errortypes.BadInput{
Message: fmt.Sprintf("Video: missing required field mimes"),
Message: "Video: missing required field mimes",
}
}

if (imp.Video.H == nil || *imp.Video.H == 0) && (imp.Video.W == nil || *imp.Video.W == 0) {
return &errortypes.BadInput{
Message: fmt.Sprintf("Video: Need at least one size to build request"),
Message: "Video: Need at least one size to build request",
}
}

Expand Down
8 changes: 4 additions & 4 deletions adapters/connectad/connectad.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ func (a *ConnectAdAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *a

if errs := preprocess(request); len(errs) > 0 {
return nil, append(errs, &errortypes.BadInput{
Message: fmt.Sprintf("Error in preprocess of Imp"),
Message: "Error in preprocess of Imp",
})
}

data, err := json.Marshal(request)
if err != nil {
return nil, []error{&errortypes.BadInput{
Message: fmt.Sprintf("Error in packaging request to JSON"),
Message: "Error in packaging request to JSON",
}}
}

Expand Down Expand Up @@ -183,7 +183,7 @@ func buildImpBanner(imp *openrtb2.Imp) error {

if imp.Banner == nil {
return &errortypes.BadInput{
Message: fmt.Sprintf("We need a Banner Object in the request"),
Message: "We need a Banner Object in the request",
}
}

Expand All @@ -193,7 +193,7 @@ func buildImpBanner(imp *openrtb2.Imp) error {

if len(banner.Format) == 0 {
return &errortypes.BadInput{
Message: fmt.Sprintf("At least one size is required"),
Message: "At least one size is required",
}
}
format := banner.Format[0]
Expand Down
2 changes: 0 additions & 2 deletions adapters/consumable/consumable.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,10 @@ func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.R

bidResponse := adapters.NewBidderResponseWithBidsCapacity(len(request.Imp))
bidResponse.Currency = response.Cur
var errors []error
for _, seatBid := range response.SeatBid {
for i, bid := range seatBid.Bid {
bidType, err := getMediaTypeForBid(bid)
if err != nil {
errors = append(errors, err)
continue
}
var bidVideo *openrtb_ext.ExtBidPrebidVideo
Expand Down
4 changes: 2 additions & 2 deletions adapters/deepintent/deepintent.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func buildImpBanner(imp *openrtb2.Imp) error {

if imp.Banner == nil {
return &errortypes.BadInput{
Message: fmt.Sprintf("We need a Banner Object in the request"),
Message: "We need a Banner Object in the request",
}
}

Expand All @@ -161,7 +161,7 @@ func buildImpBanner(imp *openrtb2.Imp) error {

if len(banner.Format) == 0 {
return &errortypes.BadInput{
Message: fmt.Sprintf("At least one size is required"),
Message: "At least one size is required",
}
}
format := banner.Format[0]
Expand Down
2 changes: 1 addition & 1 deletion adapters/definemedia/definemedia.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func getMediaTypeForBid(bid openrtb2.Bid) (openrtb_ext.BidType, error) {
return openrtb_ext.ParseBidType(string(bidExt.Prebid.Type))
}
return "", &errortypes.BadServerResponse{
Message: fmt.Sprintf("Invalid mediatype in the impression"),
Message: "Invalid mediatype in the impression",
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions adapters/dmx/dmx.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,13 @@ func (adapter *DmxAdapter) MakeBids(request *openrtb2.BidRequest, externalReques

if http.StatusBadRequest == response.StatusCode {
return nil, []error{&errortypes.BadInput{
Message: fmt.Sprintf("Unexpected status code 400"),
Message: "Unexpected status code 400",
}}
}

if http.StatusOK != response.StatusCode {
return nil, []error{&errortypes.BadInput{
Message: fmt.Sprintf("Unexpected response no status code"),
Message: "Unexpected response no status code",
}}
}

Expand Down
2 changes: 1 addition & 1 deletion adapters/e_volution/evolution.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (a *adapter) MakeBids(

if len(bidResp.SeatBid) == 0 {
return nil, []error{&errortypes.BadServerResponse{
Message: fmt.Sprintf("Empty seatbid"),
Message: "Empty seatbid",
}}
}

Expand Down
2 changes: 1 addition & 1 deletion adapters/gamma/gamma.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func (a *GammaAdapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRe
})
} else {
err := &errortypes.BadServerResponse{
Message: fmt.Sprintf("Missing Ad Markup. Run with request.debug = 1 for more info"),
Message: "Missing Ad Markup. Run with request.debug = 1 for more info",
}
errs = append(errs, err)
}
Expand Down
2 changes: 1 addition & 1 deletion adapters/gamoshi/gamoshi.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (a *GamoshiAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *ada

if !validImpExists {
err := &errortypes.BadInput{
Message: fmt.Sprintf("No valid impression in the bid request"),
Message: "No valid impression in the bid request",
}
errs = append(errs, err)
return nil, errs
Expand Down
10 changes: 9 additions & 1 deletion adapters/grid/grid.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package grid

import (
"encoding/json"
"errors"
"fmt"
"net/http"
"sort"
Expand Down Expand Up @@ -394,8 +395,12 @@ func (a *GridAdapter) MakeBids(internalRequest *openrtb2.BidRequest, externalReq

for _, sb := range bidResp.SeatBid {
for i := range sb.Bid {
bidMeta, err := getBidMeta(sb.Bid[i].Ext)
bidMeta, err := getBidMeta(sb.Bid[i].Ext) //nolint: ineffassign,staticcheck // ineffectual assignment to err

bidType, err := getMediaTypeForImp(sb.Bid[i].ImpID, internalRequest.Imp, sb.Bid[i])
if err != nil {
return nil, []error{err}
}
if sb.Bid[i].AdmNative != nil && sb.Bid[i].AdM == "" {
if bytes, err := json.Marshal(sb.Bid[i].AdmNative); err == nil {
sb.Bid[i].AdM = string(bytes)
Expand Down Expand Up @@ -427,6 +432,9 @@ func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server co
}

func getBidMeta(ext json.RawMessage) (*openrtb_ext.ExtBidPrebidMeta, error) {
if ext == nil {
return nil, errors.New("nil ext passed to getBidMeta")
}
var bidExt GridBidExt

if err := json.Unmarshal(ext, &bidExt); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions adapters/imds/imds.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (a *adapter) makeRequest(request *openrtb2.BidRequest) (*adapters.RequestDa
// if the bid request is missing seatId or TagId then ignore it
if validExtImpObj.SeatId == "" || validExtImpObj.TagId == "" {
errs = append(errs, &errortypes.BadServerResponse{
Message: fmt.Sprintf("Invalid Impression"),
Message: "Invalid Impression",
})
continue
}
Expand All @@ -91,7 +91,7 @@ func (a *adapter) makeRequest(request *openrtb2.BidRequest) (*adapters.RequestDa

if firstExtImp == nil || firstExtImp.SeatId == "" || firstExtImp.TagId == "" {
return nil, append(errs, &errortypes.BadServerResponse{
Message: fmt.Sprintf("Invalid Impression"),
Message: "Invalid Impression",
})
}
// this is where the empty seatId is filled
Expand Down
2 changes: 1 addition & 1 deletion adapters/mobfoxpb/mobfoxpb.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.E
key, errKey := jsonparser.GetString(imp.Ext, "bidder", "key")
if errTag != nil && errKey != nil {
errs = append(errs, &errortypes.BadInput{
Message: fmt.Sprintf("Invalid or non existing key and tagId, atleast one should be present"),
Message: "Invalid or non existing key and tagId, at least one should be present",
})
return nil, errs
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},
"expectedMakeRequestsErrors": [
{
"value": "Invalid or non existing key and tagId, atleast one should be present",
"value": "Invalid or non existing key and tagId, at least one should be present",
"comparison": "literal"
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"expectedMakeRequestsErrors": [
{
"value": "Invalid or non existing key and tagId, atleast one should be present",
"value": "Invalid or non existing key and tagId, at least one should be present",
"comparison": "literal"
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"expectedMakeRequestsErrors": [
{
"value": "Invalid or non existing key and tagId, atleast one should be present",
"value": "Invalid or non existing key and tagId, at least one should be present",
"comparison": "literal"
}
]
Expand Down
2 changes: 1 addition & 1 deletion adapters/nobid/nobid.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (a *NoBidAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapt

if len(request.Imp) == 0 {
return nil, []error{&errortypes.BadInput{
Message: fmt.Sprintf("No Imps in Bid Request"),
Message: "No Imps in Bid Request",
}}
}

Expand Down
Loading

0 comments on commit 1979036

Please sign in to comment.