Reputation: 121
Given these structs:
type InitRequest struct {
ListenAddr string
ForceNewCluster bool
Spec Spec
}
type Spec struct {
Annotations
AcceptancePolicy AcceptancePolicy `json:",omitempty"`
//...
}
type AcceptancePolicy struct {
Policies []Policy `json:",omitempty"`
}
type Policy struct {
Role NodeRole
Autoaccept bool
Secret *string `json:",omitempty"`
}
This code doesn't compile, exiting on that line with missing type in composite literal. Followed Go, Golang : array type inside struct, missing type composite literal , but same error with:
swarm, err := cli.SwarmInit(context.Background(), swarm.InitRequest{
ListenAddr: "0.0.0.0:2377",
ForceNewCluster: true,
Spec: {
AcceptancePolicy: {
Policies: []Policy{
Policy: {
Role: "manager",
Autoaccept: true,
},
},
}, // here
},
})
Any hint will be very helpful, thanks!
Upvotes: 1
Views: 4649
Reputation: 40789
I identified a few issues with your code:
AcceptancePolicy
is a slice not a mapAcceptancePolicy
or the Spec
.Role
is a NodeRole
, not a stringHere's your code with the above fixes implemented:
mySwarm, err := cli.SwarmInit(context.Background(), swarm.InitRequest{
ListenAddr: "0.0.0.0:2377",
ForceNewCluster: true,
Spec: swarm.Spec{
AcceptancePolicy: swarm.AcceptancePolicy{
Policies: []swarm.Policy{
{
Role: some.conversion.to.NodeRole("manager"),
Autoaccept: true,
},
},
}, // here
},
})
Upvotes: 6