Below is a snippet of my code. I need to pass a json body that has a field name "type" in it. I can create the body as a string, but I was trying to leverage structs. Obviously, trying to create a variable named 'type' in the struct throws errors. As "type" as a field name is common in json, I was wondering how others have solved for this situation. I have been googling for possible solutions, but finding the right mix of search terms has proven challenging.
package main
import (
"fmt"
"encoding/json"
)
type LoginRequest struct {
username string
password string
}
func createsession() {
_, err := resty.R().
SetHeader("Content-Type", "application/json").
SetBody(`{"type": "APISession","version": {"type": "APIVersion","major": 1,"minor": 6,"micro": 0}}`).
if err != nil {
panic(err)
}
}
func login() {
_, err := resty.R().
SetHeader("Content-Type", "application/json").
SetBody(LoginRequest{username: "my_admin", password: "testing123"}).
//SetBody(`{"type": "LoginRequest","username": "my_admin","password": "testing123"}` //this works
}
func main ()
createsession()
login()