# DHIS2 Go SDK
This is a Go-based SDK for interacting with the DHIS2 Web API, supporting:
- Tracker and Aggregate payloads
- Query parameter construction
- Typed request and response models
- Structured error handling
- Auto-generated schema models from DHIS2's OpenAPI spec
---
## π¦ Package Structure
```text
dhis2/
βββ client.go # HTTP client using Resty
βββ query/ # Chainable query param builder
βββ response/ # Response summaries (e.g. import status)
βββ error/ # Custom DHIS2-aware error types
βββ schema/ # Auto-generated models (Event, TEI, etc.)
βββ generate-schema.sh # Rebuild schema/ using OpenAPI spec
```
---
## β
Getting Started
### Installation
```bash
go get
github.com
```
### Example Usage
```go
package main
import (
"log"
"
github.com"
"
github.com"
)
func main() {
client := dhis2.NewClient("
your-dhis2.org", "admin", "district")
event := &schema.Event{
Program: "abc123",
OrgUnit: "xyz789",
Status: "ACTIVE",
}
resp, err := client.Post("/api/events", event)
if err != nil {
log.Fatalf("Error: %v", err)
}
log.Println("β
Submitted event successfully:", resp.Status())
}
```
---
## π§± Schema Models (`schema/`)
The `schema/` package contains Go types auto-generated from DHIS2's OpenAPI spec (v40+). Only the models listed in `models.txt` are retained and cleaned.
Each model file is:
- Formatted with `goimports` or `gofmt`
- Version-controlled and reproducible
---
## βοΈ Regenerating Models
To regenerate the schema types after a DHIS2 upgrade:
```bash
./generate-schema.sh
```
This will:
1. Download the latest OpenAPI spec
2. Generate all models
3. Retain only models listed in `models.txt`
4. Rename and format `.go` files
---
## π§° Dependencies
- Go 1.19+
- Resty
- `goimports` (optional but recommended)
Install dependencies:
```bash
go install
golang.org β¦