Complete package for generating ocds structs (with extensions) in golang
This commit is contained in:
1 parent
da726550d4
commit
35974fa070
47 files changed
+9861
-299
No files matched your search
@@ -0,0 +1,32 @@
|
||||
// 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))
|
||||
}
|
||||
Reference in new issue
Block a user