-
Notifications
You must be signed in to change notification settings - Fork 85
Description
The examples at https://www.haproxy.com/documentation/hapee/1-9r1/configuration/dataplaneapi/ are incompatible with the Golang client bindings generated from the OpenAPI spec. Aside from having to create a program to remove the duplicate Opt
structs, I've also had to do yet some more post-processing to make the Backend
model compatible with the aforementioned examples:
.PHONY: fix-backend-model
fix-backend-model: | $(GOLANGCI_LINT)
fix-backend-model: $(OUTPUT_DIR)/model_backend.go
fix-backend-model: ## Makes optional fields in the backend model into pointers
sed -i.bak \
-e 's~Forwardfor[[:space:]]\{1,\}Forwardfor~Forwardfor *Forwardfor~' \
-e 's~HashType[[:space:]]\{1,\}BackendHashType~HashType *BackendHashType~' \
-e 's~StickTable[[:space:]]\{1,\}BackendStickTable~StickTable *BackendStickTable~' \
$<
$(GOLANGCI_LINT) run -v --no-config --fast=false --fix --disable-all --enable goimports $<
@rm -f $<.bak
If those fields aren't pointers, then you end up with obtuse errors (when using transactions) as a result of trying to create a new backend. While the values of Forwardfor.Enabled
, HashType.Method
, BackendStickTable.Type
, and BackendStickTable.Size
may all be tagged as omitempty
, the server disagrees when empty values are submitted for the struct (and thus its fields).
I had to do the following to get a backend successfully created in Golang, and I'm not even sure if those values are the defaults for those fields.
// Create a backend.
backend, _, err := client.BackendApi.CreateBackend(ctx, hapi.Backend{
Name: "lb-backend",
Mode: "tcp",
Balance: hapi.Balance{
Algorithm: "roundrobin",
},
Forwardfor: hapi.Forwardfor{
Enabled: "enabled",
},
HashType: hapi.BackendHashType{
Method: "consistent",
},
Redispatch: hapi.Redispatch{
Enabled: "disabled",
},
AdvCheck: "tcp-check",
StickTable: hapi.BackendStickTable{
Type: "ip2",
Size: ptrInt32(100),
},
}, &hapi.CreateBackendOpts{
TransactionId: transactionID,
})
if err != nil {
t.Fatalf("failed to create backend: %v", err)
}