33 lines
1.1 KiB
Go
33 lines
1.1 KiB
Go
// Command myapp shows three packages, each with its own extension set, used side by side.
|
|
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"log"
|
|
|
|
"example.com/myapp/internal/budgets"
|
|
"example.com/myapp/internal/tenders"
|
|
"git.avsdev.uk/Go/go-ocds/profiles/uk"
|
|
)
|
|
|
|
const data = `{"ocid":"ocds-1","id":"r1","date":"2026-09-01T00:00:00Z","tag":["tender"],"initiationType":"tender",
|
|
"planning":{"budget":{"id":"B1","budgetBreakdown":[{"id":"BB1","amount":{"amount":500,"currency":"GBP"}}]}},
|
|
"tender":{"id":"T1","lots":[{"id":"L1","suitability":{"sme":true}}]}}`
|
|
|
|
func main() {
|
|
// The same JSON decodes into each package; each one sees only the fields
|
|
// its extensions define (other fields are ignored on decode).
|
|
var t tenders.Release
|
|
var b budgets.Release
|
|
var u uk.Release
|
|
for _, v := range []any{&t, &b, &u} {
|
|
if err := json.Unmarshal([]byte(data), v); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
fmt.Println("tenders: lot L1 SME-suitable =", *t.Tender.Lots[0].Suitability.SME)
|
|
fmt.Println("budgets: breakdown amount =", *b.Planning.Budget.BudgetBreakdown[0].Amount.Amount)
|
|
fmt.Println("uk: lots =", len(u.Tender.Lots))
|
|
}
|