Skip to content

Commit 269e690

Browse files
committed
adapters. on test.
1 parent 04673bb commit 269e690

File tree

14 files changed

+65
-14
lines changed

14 files changed

+65
-14
lines changed

cmd/app/main.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ import (
1313
zaplogger "github.com/RapidCodeLab/ZapLogger"
1414
browscap_devicedetector "github.com/RapidCodeLab/rapid-prebid-server/device-detectors/browscap"
1515
default_config_provider "github.com/RapidCodeLab/rapid-prebid-server/dsp-adapters/config-providers/default"
16+
boltdb_entity_provider "github.com/RapidCodeLab/rapid-prebid-server/entity-providers/boltdb"
1617
geoip2_detector "github.com/RapidCodeLab/rapid-prebid-server/geo-detectors/geoip2"
1718
"github.com/RapidCodeLab/rapid-prebid-server/internal/application/core"
1819
"github.com/RapidCodeLab/rapid-prebid-server/internal/application/interfaces"
1920
"github.com/RapidCodeLab/rapid-prebid-server/internal/application/server"
20-
inventoryapiboltdb "github.com/RapidCodeLab/rapid-prebid-server/inventory-api/boltdb"
21+
inventorystorage_boltdb "github.com/RapidCodeLab/rapid-prebid-server/inventory-storage/boltdb"
2122
)
2223

2324
type Config struct {
@@ -66,7 +67,7 @@ func main() {
6667
config.ServerListeNetwork,
6768
config.ServerListenAddr)
6869

69-
invStorager, err := inventoryapiboltdb.New(
70+
invStorager, err := inventorystorage_boltdb.New(
7071
ctx,
7172
config.BoltDBPath,
7273
l)
@@ -75,6 +76,10 @@ func main() {
7576
os.Exit(1)
7677
}
7778

79+
entityProvider := boltdb_entity_provider.New(
80+
invStorager,
81+
)
82+
7883
deviceDetector, err := browscap_devicedetector.New(
7984
config.DeviceDBPath,
8085
)
@@ -109,6 +114,7 @@ func main() {
109114
err = app.Start(
110115
ctx,
111116
invStorager,
117+
entityProvider,
112118
deviceDetector,
113119
geoDetector,
114120
enabledDSPAdapters,

dsp-adapters/config-providers/default/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (i *provider) Read(
6060
interfaces.DSPAdapterConfig,
6161
error,
6262
) {
63-
return interfaces.DSPAdapterConfig{}, nil
63+
return i.data[name], nil
6464
}
6565

6666
func findFiles(root, ext string) ([]string, error) {

dsp-adapters/default/main.go

+4
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,9 @@ func NewDSPAdpater(
6767
Name: c.Name,
6868
httpClient: &fasthttp.Client{},
6969
endpintURI: c.Endpoint,
70+
requestTimout: time.Duration(
71+
time.Duration(c.RequestTimout) *
72+
time.Millisecond,
73+
),
7074
}, nil
7175
}

dsp-configs/demo-dsp-1.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"name":"demo-dsp-1",
3-
"enpoint":"http:/127.0.0.1:8060/rtb"
3+
"endpoint":"http://127.0.0.1:8060/rtb",
4+
"request_timeout":500
45
}

entity-providers/boltdb/main.go

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package boltdb_entity_provider
2+
3+
import "github.com/RapidCodeLab/rapid-prebid-server/internal/application/interfaces"
4+
5+
type provider struct {
6+
storage interfaces.EntityReadStorager
7+
}
8+
9+
func New(
10+
s interfaces.EntityReadStorager,
11+
) interfaces.EntityProvider {
12+
return &provider{
13+
storage: s,
14+
}
15+
}
16+
17+
func (i *provider) Provide(
18+
entityID string,
19+
) (interfaces.Entity, error) {
20+
return i.storage.ReadEntity(entityID)
21+
}

geo-detectors/geoip2/detector.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,13 @@ func (l *GeoLocator) Detect(
3737
}
3838

3939
data.CountryCode = d.Country.IsoCode
40-
data.Region = d.Subdivisions[0].Names[l.namesLanguage]
41-
data.City = d.City.Names[l.namesLanguage]
40+
if len(d.Subdivisions) > 0 {
41+
data.Region = d.Subdivisions[0].Names[l.namesLanguage]
42+
}
43+
cityName, ok := d.City.Names[l.namesLanguage]
44+
if ok {
45+
data.City = cityName
46+
}
4247

4348
return data, nil
4449
}

internal/application/core/core.go

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ type payloadHTTPServer interface {
1010
Start(
1111
context.Context,
1212
interfaces.InventoryStorager,
13+
interfaces.EntityProvider,
1314
interfaces.DeviceDetector,
1415
interfaces.GeoDetector,
1516
[]interfaces.DSPName,
@@ -33,6 +34,7 @@ func New(s payloadHTTPServer,
3334

3435
func (i *Core) Start(ctx context.Context,
3536
invStorager interfaces.InventoryStorager,
37+
entityProvider interfaces.EntityProvider,
3638
deviceDetector interfaces.DeviceDetector,
3739
geoDetector interfaces.GeoDetector,
3840
enabledDSPAdapters []interfaces.DSPName,
@@ -41,6 +43,7 @@ func (i *Core) Start(ctx context.Context,
4143
return i.payloadHTTPServer.Start(
4244
ctx,
4345
invStorager,
46+
entityProvider,
4447
deviceDetector,
4548
geoDetector,
4649
enabledDSPAdapters,

internal/application/handlers/payload/payload.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ func (h *Handler) Handle(ctx *fasthttp.RequestCtx) {
3737
)
3838
}
3939

40+
if len(entities) < 1 {
41+
ctx.SetStatusCode(fasthttp.StatusNotFound)
42+
return
43+
}
44+
4045
deviceData := h.deviceDetector.Detect(
4146
string(ctx.UserAgent()),
4247
)
@@ -90,7 +95,7 @@ func (h *Handler) Handle(ctx *fasthttp.RequestCtx) {
9095
}()
9196
}
9297

93-
wg.Done()
98+
wg.Wait()
9499

95100
winners := default_auction.Auction(responses)
96101

internal/application/interfaces/dsp_adapter.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ type DSPAdapter interface {
1818
}
1919

2020
type DSPAdapterConfig struct {
21-
Name DSPName `json:"name"`
22-
Endpoint string `json:"endpoint"`
21+
Name DSPName `json:"name"`
22+
Endpoint string `json:"endpoint"`
23+
RequestTimout int64 `json:"request_timeout"`
2324
}
2425

2526
type NewDSPAdapter func(DSPAdapterConfig) (DSPAdapter, error)

internal/application/interfaces/inventory_api.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,13 @@ type InventoryStorager interface {
4848
}
4949

5050
type EntityStorager interface {
51+
EntityReadStorager
5152
ReadAllEntities() ([]Entity, error)
5253
CreateEntity(Entity) error
53-
ReadEntity(ID string) (Entity, error)
5454
UpdateEntity(Entity) error
5555
DeleteEntity(ID string) error
5656
}
57+
58+
type EntityReadStorager interface {
59+
ReadEntity(ID string) (Entity, error)
60+
}

internal/application/server/main.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func New(l interfaces.Logger,
3737
func (i *Server) Start(
3838
ctx context.Context,
3939
invStorager interfaces.InventoryStorager,
40+
entityProvider interfaces.EntityProvider,
4041
deviceDetector interfaces.DeviceDetector,
4142
geoDetector interfaces.GeoDetector,
4243
enabledAdapters []interfaces.DSPName,
@@ -73,7 +74,7 @@ func (i *Server) Start(
7374
i.logger,
7475
deviceDetector,
7576
geoDetector,
76-
nil,
77+
entityProvider,
7778
adapters,
7879
)
7980
payloadHandler.LoadRoutes(r)

inventory-api/boltdb/entity.go inventory-storage/boltdb/entity.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package inventoryapiboltdb
1+
package inventorystorage_boltdb
22

33
import (
44
"encoding/json"

inventory-api/boltdb/inventory.go inventory-storage/boltdb/inventory.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package inventoryapiboltdb
1+
package inventorystorage_boltdb
22

33
import (
44
"encoding/json"

inventory-api/boltdb/main.go inventory-storage/boltdb/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package inventoryapiboltdb
1+
package inventorystorage_boltdb
22

33
import (
44
"context"

0 commit comments

Comments
 (0)