Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issues flagged by golangci-lint #3621

Merged
merged 12 commits into from
May 6, 2024
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 {
dmitris marked this conversation as resolved.
Show resolved Hide resolved
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
2 changes: 1 addition & 1 deletion adapters/lemmadigital/lemmadigital.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.R
}
bidResponse.Bids = append(bidResponse.Bids, b)
}
break
break //nolint: staticcheck // break is intended, exempt from staticcheck SA4004
guscarreon marked this conversation as resolved.
Show resolved Hide resolved
}

return bidResponse, nil
Expand Down
1 change: 1 addition & 0 deletions adapters/minutemedia/minutemedia.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func extractOrg(openRTBRequest *openrtb2.BidRequest) (string, error) {
return "", fmt.Errorf("failed to unmarshal ImpExtMinuteMedia: %w", err)
}

//nolint: staticcheck // SA4004: the surrounding loop is unconditionally terminated
return strings.TrimSpace(impExt.Org), nil
guscarreon marked this conversation as resolved.
Show resolved Hide resolved
}

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(),
}
}
AlexBVolcy marked this conversation as resolved.
Show resolved Hide resolved
if isNewEndpoint {
tappxHost = params.Endpoint + ".pub.tappx.com/rtb/"
} else {
Expand Down
8 changes: 6 additions & 2 deletions adapters/tappx/tappx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/prebid/prebid-server/v2/config"
"github.com/prebid/prebid-server/v2/openrtb_ext"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestJsonSamples(t *testing.T) {
Expand Down Expand Up @@ -38,13 +39,16 @@ func TestTsValue(t *testing.T) {

bidderTappx := bidder.(*TappxAdapter)

var test int
test = 0
test := 0
var tappxExt openrtb_ext.ExtImpTappx
tappxExt.Endpoint = "DUMMYENDPOINT"
tappxExt.TappxKey = "dummy-tappx-key"

url, err := bidderTappx.buildEndpointURL(&tappxExt, test)
if err != nil {
require.NoError(t, err, "buildEndpointURL")
guscarreon marked this conversation as resolved.
Show resolved Hide resolved
return
}
AlexBVolcy marked this conversation as resolved.
Show resolved Hide resolved

match, err := regexp.MatchString(`http://ssp\.api\.tappx\.com/rtb/v2/DUMMYENDPOINT\?tappxkey=dummy-tappx-key&ts=[0-9]{13}&type_cnn=prebid&v=1\.5`, url)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions adapters/yieldlab/yieldlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,20 +498,20 @@ func makeSupplyChain(openRtbSchain openrtb2.SupplyChain) string {

// makeNodeValue converts any known value type from a schain node to a string and does URL encoding if necessary.
func makeNodeValue(nodeParam any) string {
switch nodeParam.(type) {
switch nodeParam := nodeParam.(type) {
case string:
return url.QueryEscape(nodeParam.(string))
return url.QueryEscape(nodeParam)
case *int8:
pointer := nodeParam.(*int8)
pointer := nodeParam
if pointer == nil {
return ""
}
return makeNodeValue(int(*pointer))
case int:
return strconv.Itoa(nodeParam.(int))
return strconv.Itoa(nodeParam)
case json.RawMessage:
if freeFormData := nodeParam.(json.RawMessage); freeFormData != nil {
freeFormJson, err := json.Marshal(freeFormData)
if nodeParam != nil {
freeFormJson, err := json.Marshal(nodeParam)
if err != nil {
return ""
}
Expand Down
Loading
Loading