Skip to content

Commit

Permalink
Fix issues flagged by golangci-lint (prebid#3621)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitris authored and mefjush committed Jul 19, 2024
1 parent 42a453f commit 61ae74f
Show file tree
Hide file tree
Showing 40 changed files with 164 additions and 181 deletions.
4 changes: 2 additions & 2 deletions account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
func GetAccount(ctx context.Context, cfg *config.Configuration, fetcher stored_requests.AccountFetcher, accountID string, me metrics.MetricsEngine) (account *config.Account, errs []error) {
if cfg.AccountRequired && accountID == metrics.PublisherUnknown {
return nil, []error{&errortypes.AcctRequired{
Message: fmt.Sprintf("Prebid-server has been configured to discard requests without a valid Account ID. Please reach out to the prebid server host."),
Message: "Prebid-server has been configured to discard requests without a valid Account ID. Please reach out to the prebid server host.",
}}
}

Expand All @@ -32,7 +32,7 @@ func GetAccount(ctx context.Context, cfg *config.Configuration, fetcher stored_r
}
if cfg.AccountRequired && cfg.AccountDefaults.Disabled {
errs = append(errs, &errortypes.AcctRequired{
Message: fmt.Sprintf("Prebid-server could not verify the Account ID. Please reach out to the prebid server host."),
Message: "Prebid-server could not verify the Account ID. Please reach out to the prebid server host.",
})
return nil, errs
}
Expand Down
2 changes: 1 addition & 1 deletion adapters/adkernelAdn/adkernelAdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func compatBannerImpression(imp *openrtb2.Imp) error {
//As banner.w/h are required fields for adkernelAdn platform - take the first format entry
if banner.W == nil && banner.H == nil {
if len(banner.Format) == 0 {
return newBadInputError(fmt.Sprintf("Expected at least one banner.format entry or explicit w/h"))
return newBadInputError("Expected at least one banner.format entry or explicit w/h")
}
format := banner.Format[0]
banner.Format = banner.Format[1:]
Expand Down
6 changes: 3 additions & 3 deletions adapters/adnuntius/adnuntius.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func (a *adapter) generateRequests(ortbRequest openrtb2.BidRequest) ([]*adapters
}}
}

if adnuntiusExt.NoCookies == true {
if adnuntiusExt.NoCookies {
noCookies = true
}

Expand Down Expand Up @@ -463,7 +463,7 @@ func generateBidResponse(adnResponse *AdnResponse, request *openrtb2.BidRequest)
adBid, err := generateAdResponse(ad, imp, adunit.Html, request)
if err != nil {
return nil, []error{&errortypes.BadInput{
Message: fmt.Sprintf("Error at ad generation"),
Message: "Error at ad generation",
}}
}

Expand All @@ -476,7 +476,7 @@ func generateBidResponse(adnResponse *AdnResponse, request *openrtb2.BidRequest)
dealBid, err := generateAdResponse(deal, imp, deal.Html, request)
if err != nil {
return nil, []error{&errortypes.BadInput{
Message: fmt.Sprintf("Error at ad generation"),
Message: "Error at ad generation",
}}
}

Expand Down
5 changes: 5 additions & 0 deletions adapters/adtelligent/adtelligent.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ func validateImpression(imp *openrtb2.Imp) (int, error) {
impExtBuffer, err = json.Marshal(&adtelligentImpExt{
Adtelligent: impExt,
})
if err != nil {
return 0, &errortypes.BadInput{
Message: fmt.Sprintf("ignoring imp id=%s, error while marshaling impExt, err: %s", imp.ID, err),
}
}

if impExt.BidFloor > 0 {
imp.BidFloor = impExt.BidFloor
Expand Down
3 changes: 3 additions & 0 deletions adapters/avocet/avocet.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ func (a *AvocetAdapter) MakeBids(internalRequest *openrtb2.BidRequest, externalR
bidResponse.Bids = append(bidResponse.Bids, tbid)
}
}
if len(errs) > 0 {
return nil, errs
}
return bidResponse, nil
}

Expand Down
4 changes: 1 addition & 3 deletions adapters/beintoo/beintoo.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (a *BeintooAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *ada
}}
}

if errors := preprocess(request); errors != nil && len(errors) > 0 {
if errors := preprocess(request); len(errors) > 0 {
return nil, append(errors, &errortypes.BadInput{
Message: fmt.Sprintf("Error in preprocess of Imp, err: %s", errors),
})
Expand Down Expand Up @@ -133,8 +133,6 @@ func addImpProps(imp *openrtb2.Imp, secure *int8, BeintooExt *openrtb_ext.ExtImp
imp.BidFloor = bidFloor
}
}

return
}

// Adding header fields to request header
Expand Down
2 changes: 1 addition & 1 deletion adapters/between/between.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (a *BetweenAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *ada
}}
}
ext, errors := preprocess(request)
if errors != nil && len(errors) > 0 {
if len(errors) > 0 {
return nil, errors
}
endpoint, err := a.buildEndpointURL(ext)
Expand Down
4 changes: 1 addition & 3 deletions adapters/cadent_aperture_mx/cadentaperturemx.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.E
}}
}

if errs := preprocess(request); errs != nil && len(errs) > 0 {
if errs := preprocess(request); len(errs) > 0 {
return nil, append(errs, &errortypes.BadInput{
Message: fmt.Sprintf("Error in preprocess of Imp, err: %s", errs),
})
Expand Down Expand Up @@ -192,8 +192,6 @@ func addImpProps(imp *openrtb2.Imp, secure *int8, cadentExt *openrtb_ext.ExtImpC
imp.BidFloorCur = "USD"
}
}

return
}

// Adding header fields to request header
Expand Down
2 changes: 0 additions & 2 deletions adapters/connectad/connectad.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ func addImpInfo(imp *openrtb2.Imp, secure *int8, cadExt *openrtb_ext.ExtImpConne
imp.BidFloor = cadExt.Bidfloor
imp.BidFloorCur = "USD"
}

return
}

func addHeaderIfNonEmpty(headers http.Header, headerName string, headerValue string) {
Expand Down
3 changes: 0 additions & 3 deletions adapters/consumable/consumable.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,10 @@ func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.R
switch bidType {
case openrtb_ext.BidTypeAudio:
seatBid.Bid[i].MType = openrtb2.MarkupAudio
break
case openrtb_ext.BidTypeVideo:
seatBid.Bid[i].MType = openrtb2.MarkupVideo
break
case openrtb_ext.BidTypeBanner:
seatBid.Bid[i].MType = openrtb2.MarkupBanner
break
}
bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{
Bid: &seatBid.Bid[i],
Expand Down
35 changes: 17 additions & 18 deletions adapters/dmx/dmx.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ func (adapter *DmxAdapter) MakeRequests(request *openrtb2.BidRequest, req *adapt
var publisherId string
var sellerId string
var userExt openrtb_ext.ExtUser
var anyHasId = false
var reqCopy openrtb2.BidRequest = *request
var dmxReq *openrtb2.BidRequest = &reqCopy
var dmxRawPubId dmxPubExt
Expand All @@ -85,6 +84,7 @@ func (adapter *DmxAdapter) MakeRequests(request *openrtb2.BidRequest, req *adapt
}
}

hasNoID := true
if request.App != nil {
appCopy := *request.App
appPublisherCopy := *request.App.Publisher
Expand All @@ -101,12 +101,12 @@ func (adapter *DmxAdapter) MakeRequests(request *openrtb2.BidRequest, req *adapt
}
dmxReq.App.Publisher.Ext = ext
if dmxReq.App.ID != "" {
anyHasId = true
hasNoID = false
}
if anyHasId == false {
if hasNoID {
if idfa, valid := getIdfa(request); valid {
dmxReq.App.ID = idfa
anyHasId = true
hasNoID = false
}
}
} else {
Expand Down Expand Up @@ -145,12 +145,12 @@ func (adapter *DmxAdapter) MakeRequests(request *openrtb2.BidRequest, req *adapt

if dmxReq.User != nil {
if dmxReq.User.ID != "" {
anyHasId = true
hasNoID = false
}
if dmxReq.User.Ext != nil {
if err := json.Unmarshal(dmxReq.User.Ext, &userExt); err == nil {
if len(userExt.Eids) > 0 {
anyHasId = true
hasNoID = false
}
}
}
Expand Down Expand Up @@ -190,7 +190,7 @@ func (adapter *DmxAdapter) MakeRequests(request *openrtb2.BidRequest, req *adapt

dmxReq.Imp = imps

if anyHasId == false {
if hasNoID {
return nil, []error{errors.New("This request contained no identifier")}
}

Expand Down Expand Up @@ -264,37 +264,36 @@ func (adapter *DmxAdapter) MakeBids(request *openrtb2.BidRequest, externalReques
}

func fetchParams(params dmxExt, inst openrtb2.Imp, ins openrtb2.Imp, imps []openrtb2.Imp, banner *openrtb2.Banner, video *openrtb2.Video, intVal int8) []openrtb2.Imp {
var tempimp openrtb2.Imp
tempimp = inst
tempImp := inst
if params.Bidder.Bidfloor != 0 {
tempimp.BidFloor = params.Bidder.Bidfloor
tempImp.BidFloor = params.Bidder.Bidfloor
}
if params.Bidder.TagId != "" {
tempimp.TagID = params.Bidder.TagId
tempimp.Secure = &intVal
tempImp.TagID = params.Bidder.TagId
tempImp.Secure = &intVal
}

if params.Bidder.DmxId != "" {
tempimp.TagID = params.Bidder.DmxId
tempimp.Secure = &intVal
tempImp.TagID = params.Bidder.DmxId
tempImp.Secure = &intVal
}
if banner != nil {
if banner.H == nil || banner.W == nil {
banner.H = &banner.Format[0].H
banner.W = &banner.Format[0].W
}
tempimp.Banner = banner
tempImp.Banner = banner
}

if video != nil {
video.Protocols = checkProtocols(video)
tempimp.Video = video
tempImp.Video = video
}

if tempimp.TagID == "" {
if tempImp.TagID == "" {
return imps
}
imps = append(imps, tempimp)
imps = append(imps, tempImp)
return imps
}

Expand Down
7 changes: 3 additions & 4 deletions adapters/gamma/gamma.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (a *GammaAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapt
errs = append(errs, err)
return nil, errs
}
var invalidImpIndex = make([]int, 0, 0)
var invalidImpIndex []int

for i := 0; i < len(request.Imp); i++ {
if request.Imp[i].Banner != nil {
Expand Down Expand Up @@ -182,7 +182,7 @@ func (a *GammaAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapt
} else if len(request.Imp) == len(invalidImpIndex) {
//only true if every Imp was not a Banner or a Video
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 All @@ -205,8 +205,7 @@ func (a *GammaAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapt
}

func convertBid(gBid gammaBid, mediaType openrtb_ext.BidType) *openrtb2.Bid {
var bid openrtb2.Bid
bid = gBid.Bid
bid := gBid.Bid

if mediaType == openrtb_ext.BidTypeVideo {
//Return inline VAST XML Document (Section 6.4.2)
Expand Down
7 changes: 3 additions & 4 deletions adapters/lemmadigital/lemmadigital.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,14 @@ func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.R
if len(response.Cur) > 0 {
bidResponse.Currency = response.Cur
}
for _, seatBid := range response.SeatBid {
for i := range seatBid.Bid {
if len(response.SeatBid) > 0 {
for i := range response.SeatBid[0].Bid {
b := &adapters.TypedBid{
Bid: &seatBid.Bid[i],
Bid: &response.SeatBid[0].Bid[i],
BidType: bidType,
}
bidResponse.Bids = append(bidResponse.Bids, b)
}
break
}

return bidResponse, nil
Expand Down
22 changes: 11 additions & 11 deletions adapters/minutemedia/minutemedia.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,21 @@ func (a *adapter) MakeBids(request *openrtb2.BidRequest, _ *adapters.RequestData

func extractOrg(openRTBRequest *openrtb2.BidRequest) (string, error) {
var err error
for _, imp := range openRTBRequest.Imp {
var bidderExt adapters.ExtImpBidder
if err = json.Unmarshal(imp.Ext, &bidderExt); err != nil {
return "", fmt.Errorf("failed to unmarshal bidderExt: %w", err)
}
if len(openRTBRequest.Imp) == 0 {
return "", errors.New("no imps in bid request")
}

var impExt openrtb_ext.ImpExtMinuteMedia
if err = json.Unmarshal(bidderExt.Bidder, &impExt); err != nil {
return "", fmt.Errorf("failed to unmarshal ImpExtMinuteMedia: %w", err)
}
var bidderExt adapters.ExtImpBidder
if err = json.Unmarshal(openRTBRequest.Imp[0].Ext, &bidderExt); err != nil {
return "", fmt.Errorf("failed to unmarshal bidderExt: %w", err)
}

return strings.TrimSpace(impExt.Org), nil
var impExt openrtb_ext.ImpExtMinuteMedia
if err = json.Unmarshal(bidderExt.Bidder, &impExt); err != nil {
return "", fmt.Errorf("failed to unmarshal ImpExtMinuteMedia: %w", err)
}

return "", errors.New("no imps in bid request")
return strings.TrimSpace(impExt.Org), nil
}

func getMediaTypeForBid(bid openrtb2.Bid) (openrtb_ext.BidType, error) {
Expand Down
2 changes: 1 addition & 1 deletion adapters/rubicon/rubicon.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ func createImpsToExtMap(imps []openrtb2.Imp) (map[*openrtb2.Imp]rubiconExtImpBid
func prepareImpsToExtMap(impsToExtMap map[*openrtb2.Imp]rubiconExtImpBidder) map[*openrtb2.Imp]rubiconExtImpBidder {
preparedImpsToExtMap := make(map[*openrtb2.Imp]rubiconExtImpBidder)
for imp, bidderExt := range impsToExtMap {
if bidderExt.Bidder.BidOnMultiformat == false {
if bidderExt.Bidder.BidOnMultiformat == false { //nolint: staticcheck
impCopy := imp
preparedImpsToExtMap[impCopy] = bidderExt
continue
Expand Down
1 change: 1 addition & 0 deletions adapters/smartrtb/smartrtb.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type bidRequestExt struct {
}

// bidExt.CreativeType values.
// nolint: staticcheck // staticcheck SA9004: only the first constant in this group has an explicit type
const (
creativeTypeBanner string = "BANNER"
creativeTypeVideo = "VIDEO"
Expand Down
6 changes: 3 additions & 3 deletions adapters/sovrnXsp/sovrnXsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ type adapter struct {
// bidExt.CreativeType values.
const (
creativeTypeBanner int = 0
creativeTypeVideo = 1
creativeTypeNative = 2
creativeTypeAudio = 3
creativeTypeVideo int = 1
creativeTypeNative int = 2
creativeTypeAudio int = 3
)

// Bid response extension from XSP.
Expand Down
8 changes: 6 additions & 2 deletions adapters/tappx/tappx.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ func (a *TappxAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapt
}}
}

var test int
test = int(request.Test)
test := int(request.Test)

url, err := a.buildEndpointURL(&tappxExt, test)
if url == "" {
Expand Down Expand Up @@ -134,6 +133,11 @@ func (a *TappxAdapter) buildEndpointURL(params *openrtb_ext.ExtImpTappx, test in

tappxHost := "tappx.com"
isNewEndpoint, err := regexp.Match(`^(zz|vz)[0-9]{3,}([a-z]{2,3}|test)$`, []byte(params.Endpoint))
if err != nil {
return "", &errortypes.BadInput{
Message: "Unable to match params.Endpoint " + string(params.Endpoint) + "): " + err.Error(),
}
}
if isNewEndpoint {
tappxHost = params.Endpoint + ".pub.tappx.com/rtb/"
} else {
Expand Down
Loading

0 comments on commit 61ae74f

Please sign in to comment.