JSON input-(which is passing from postman) { "Location":"East US", "Properties":{ "BgpSettings":{ "Asn":64515, "BgpPeeringAddress":"10.128.1.1", "BgpPeeringAddresses":[ { "CustomBgpIPAddresses":[""], "IPConfigurationID":"", "DefaultBgpIPAddresses":[""], "TunnelIPAddresses":[""] } ], "PeerWeight":0 }, "Fqdn":"", "GatewayIPAddress":"10.128.1.1", "LocalNetworkAddressSpace":{ "AddressPrefixes":["11.128.0.0/16"] } },
"Tags":{
"azure_localNwGw":"local-nw"
}
}
Description
- am trying create a local network gateway in azure for setting up the vpn connection and for that i need to bind the json input to the armnetwork.LocalNetworkGateway struct type in azure.
How to reproduce
package main
import (
"github.com/gin-gonic/gin"
)
func main() {
g := gin.Default()
g.POST("localNetworkGw", func(c *gin.Context) {
ctx := context.Background()
// creates an azure client
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("Authentication failure: %+v", err)
return
}
localNetworkGatewayClient, err := armnetwork.NewLocalNetworkGatewaysClient(os.Getenv("SUBSCRIPTION_ID"), cred, nil)
if err != nil {
return
}
// var createLocalNetworkGatewayInput armnetwork.LocalNetworkGateway
var LocalNetworkGatewayInput armnetwork.LocalNetworkGateway
if bindJsonErr := c.BindJSON(&LocalNetworkGatewayInput); bindJsonErr != nil {
log.Println("bindjsonErr:- ", bindJsonErr)
c.AbortWithStatusJSON(http.StatusBadRequest, bindJsonErr)
return
}
log.Println("createLocalNetworkGatewayInput", LocalNetworkGatewayInput)// this variable supposed to be populated with the new value that are passed in json but it shows empty and nil value for all the parameters.
log.Println("location", LocalNetworkGatewayInput.Location)//naturally this also comes as nil
pollerResp, err := localNetworkGatewayClient.BeginCreateOrUpdate(ctx, resourceGroupName, localNetworkGatewayName, LocalNetworkGatewayInput, nil)
if err != nil {
log.Println("err while creating the localNwGw ", err)
return
}
resp, err := pollerResp.PollUntilDone(ctx, nil)
if err != nil {
log.Println("err while waiting ", err)
return
}
c.JSON(http.StatusOK, resp.LocalNetworkGateway)
})
g.Run(":9000")
}
Expectations
$ curl http://localhost:9000/localNetworkGw
the input json should bind to the armnetwork.localnetworkgatewayInput struct type successfully and the actual values that are just bind with local network gateway input variable should be logged and should not show the variable as empty.
## Actual result
$ curl -i http://localhost:9000/localNetworkGw
createLocalNetworkGatewayInput {
RESPONSE 400: 400 Bad Request ERROR CODE: LocationRequired
{ "error": { "code": "LocationRequired", "message": "The location property is required for this definition." } }
Environment
- go version: 1.19.4
- gin version (or commit ref): v1.8.1
- operating system: windows 11
Comment From: DebankitaBeDev
that issue has been resolved by passing the same input parameter starts with the small letters instead of capital letter .Thanks, closing the ticket.