This project is a Go microservice that routes the right campaigns to the right delivery requests based on targeting rules.
It exposes an HTTP endpoint /v1/delivery which matches active campaigns against request parameters (app, country, os) and returns the campaigns that qualify.
targeting-engine/
βββ cmd/
β βββ server/
β βββ main.go # App entrypoint
βββ internal/
β βββ delivery/
β β βββ handler.go # Delivery HTTP handler
β β βββ handler_test.go # Unit tests for delivery
β βββ campaign/
β β βββ matcher.go # Rule-matching logic
β β βββ matcher_test.go # Unit tests for matcher
β βββ db/
β β βββ store.go # In-memory campaigns + rules (later DB/Redis)
β βββ models/
β βββ types.go # Struct definitions
βββ migrations/ # (optional) SQL schema for Postgres
βββ go.mod / go.sum
βββ docker-compose.yml # (optional) Postgres/Redis setup
type Campaign struct {
ID string `json:"cid"`
Name string
Image string `json:"img"`
CTA string `json:"cta"`
Status string // "ACTIVE" or "INACTIVE"
}type TargetingRule struct {
CampaignID string
IncludeApps []string
ExcludeApps []string
IncludeCountries []string
ExcludeCountries []string
IncludeOS []string
ExcludeOS []string
}Delivery Endpoint
Request
GET /v1/delivery?app=com.gametion.ludokinggame&country=us&os=android
Response (200 OK)
[
{
"cid": "spotify",
"img": "https://somelink",
"cta": "Download"
},
{
"cid": "subwaysurfer",
"img": "https://somelink3",
"cta": "Play"
}
]
Response (204 No Content)
(no body)
Response (400 Bad Request)
{ "error": "missing app param" }
π§ͺ Testing
Run all tests:
go test ./...
Test cases cover: Rule matching logic (inclusion/exclusion). Delivery endpoint behavior (200, 204, 400).