@@ -15,8 +15,8 @@ var invalidEnabledOnlyMsg = []byte(`Invalid value for 'enabledonly' query param,
15
15
var invalidBaseAdaptersOnlyMsg = []byte (`Invalid value for 'baseadaptersonly' query param, must be of boolean type` )
16
16
17
17
// NewBiddersEndpoint builds a handler for the /info/bidders endpoint.
18
- func NewBiddersEndpoint (bidders config.BidderInfos , aliases map [ string ] string ) httprouter.Handle {
19
- responseAll , err := prepareBiddersResponseAll (bidders , aliases )
18
+ func NewBiddersEndpoint (bidders config.BidderInfos ) httprouter.Handle {
19
+ responseAll , err := prepareBiddersResponseAll (bidders )
20
20
if err != nil {
21
21
glog .Fatalf ("error creating /info/bidders endpoint all bidders response: %v" , err )
22
22
}
@@ -26,7 +26,7 @@ func NewBiddersEndpoint(bidders config.BidderInfos, aliases map[string]string) h
26
26
glog .Fatalf ("error creating /info/bidders endpoint all bidders (base adapters only) response: %v" , err )
27
27
}
28
28
29
- responseEnabledOnly , err := prepareBiddersResponseEnabledOnly (bidders , aliases )
29
+ responseEnabledOnly , err := prepareBiddersResponseEnabledOnly (bidders )
30
30
if err != nil {
31
31
glog .Fatalf ("error creating /info/bidders endpoint enabled only response: %v" , err )
32
32
}
@@ -76,7 +76,6 @@ func readQueryFlag(r *http.Request, queryParam string) (flag, ok bool) {
76
76
q := r .URL .Query ()
77
77
78
78
v , exists := q [queryParam ]
79
-
80
79
if ! exists || len (v ) == 0 {
81
80
return false , true
82
81
}
@@ -91,26 +90,13 @@ func readQueryFlag(r *http.Request, queryParam string) (flag, ok bool) {
91
90
}
92
91
}
93
92
94
- func prepareBiddersResponseAll (bidders config.BidderInfos , aliases map [string ]string ) ([]byte , error ) {
95
- bidderNames := make ([]string , 0 , len (bidders )+ len (aliases ))
96
-
97
- for name := range bidders {
98
- bidderNames = append (bidderNames , name )
99
- }
100
-
101
- for name := range aliases {
102
- bidderNames = append (bidderNames , name )
103
- }
104
-
105
- sort .Strings (bidderNames )
106
- return jsonutil .Marshal (bidderNames )
107
- }
93
+ type bidderPredicate func (config.BidderInfo ) bool
108
94
109
- func prepareBiddersResponseAllBaseOnly (bidders config.BidderInfos ) ([]byte , error ) {
95
+ func prepareResponse (bidders config.BidderInfos , p bidderPredicate ) ([]byte , error ) {
110
96
bidderNames := make ([]string , 0 , len (bidders ))
111
97
112
98
for name , info := range bidders {
113
- if len (info . AliasOf ) == 0 {
99
+ if p (info ) {
114
100
bidderNames = append (bidderNames , name )
115
101
}
116
102
}
@@ -119,36 +105,24 @@ func prepareBiddersResponseAllBaseOnly(bidders config.BidderInfos) ([]byte, erro
119
105
return jsonutil .Marshal (bidderNames )
120
106
}
121
107
122
- func prepareBiddersResponseEnabledOnly (bidders config.BidderInfos , aliases map [string ]string ) ([]byte , error ) {
123
- bidderNames := make ([]string , 0 , len (bidders )+ len (aliases ))
124
-
125
- for name , info := range bidders {
126
- if info .IsEnabled () {
127
- bidderNames = append (bidderNames , name )
128
- }
129
- }
108
+ func prepareBiddersResponseAll (bidders config.BidderInfos ) ([]byte , error ) {
109
+ filterNone := func (_ config.BidderInfo ) bool { return true }
110
+ return prepareResponse (bidders , filterNone )
111
+ }
130
112
131
- for name , bidder := range aliases {
132
- if info , ok := bidders [bidder ]; ok && info .IsEnabled () {
133
- bidderNames = append (bidderNames , name )
134
- }
135
- }
113
+ func prepareBiddersResponseAllBaseOnly (bidders config.BidderInfos ) ([]byte , error ) {
114
+ filterBaseOnly := func (info config.BidderInfo ) bool { return len (info .AliasOf ) == 0 }
115
+ return prepareResponse (bidders , filterBaseOnly )
116
+ }
136
117
137
- sort .Strings (bidderNames )
138
- return jsonutil .Marshal (bidderNames )
118
+ func prepareBiddersResponseEnabledOnly (bidders config.BidderInfos ) ([]byte , error ) {
119
+ filterEnabledOnly := func (info config.BidderInfo ) bool { return info .IsEnabled () }
120
+ return prepareResponse (bidders , filterEnabledOnly )
139
121
}
140
122
141
123
func prepareBiddersResponseEnabledOnlyBaseOnly (bidders config.BidderInfos ) ([]byte , error ) {
142
- bidderNames := make ([]string , 0 , len (bidders ))
143
-
144
- for name , info := range bidders {
145
- if info .IsEnabled () && len (info .AliasOf ) == 0 {
146
- bidderNames = append (bidderNames , name )
147
- }
148
- }
149
-
150
- sort .Strings (bidderNames )
151
- return jsonutil .Marshal (bidderNames )
124
+ filterEnabledOnlyBaseOnly := func (info config.BidderInfo ) bool { return info .IsEnabled () && len (info .AliasOf ) == 0 }
125
+ return prepareResponse (bidders , filterEnabledOnlyBaseOnly )
152
126
}
153
127
154
128
func writeBadRequest (w http.ResponseWriter , data []byte ) {
0 commit comments