I'm trying to use some autocomplete in my code. The idea is that i use Go generate to create the file below (without the main function) so the maps and the structs. The one that uses that generated file could then create a new order using the structs and the provided options
I run into a couple of issues:
When i create a new instance of a class in node i have intelligence of the variables that the class needs. In Go when i do: order := Order{ there is nothing showing up to help the coder select fields.
As you can see i'm trying to create some options that will "translate" Car to 1 because that is needed in the JSON. But i want more readable code and provide all the options. In Node i can just do:
TransportTypeOptions.car
on a object and when im at the dot i have a dropdown with the 3 options to choose from. So i would like to see the options when i'm at point X:int64(TransportTypeOptions[X])
I hope i'm asking my question clear enough. And using VScode.
The code:
package main
import (
"encoding/json"
"fmt"
)
var TransportTypeOptions = map[string]int{
"car": 1,
"plain": 2,
"boot": 3,
}
var RelationTypeOptions = map[string]int{
"organisation": 1,
"private": 2,
}
type Order struct {
OrderNumber int64 `json:"OrNu"`
RelationType int64 `json:"OrPe"`
TransportType int64 `json:"VaTr"`
Addres *Addres `json:"address"`
}
type Addres struct {
Street string `json:"street"`
Housenumber int64 `json:"housenumber"`
}
func main() {
order := Order{
OrderNumber: 776655,
TransportType: int64(TransportTypeOptions["car"]),
RelationType: int64(RelationTypeOptions["organisation"]),
Addres: &Addres{
Street: "Somestreet",
Housenumber: 4453,
}}
json, _ := json.MarshalIndent(order, "", " ")
fmt.Println(string(json))
}
EDIT: After @Brits comment I changed the maps to:
const (
Sales_Order_Transport_Car = iota + 1
Sales_Order_Transport_Plan
Sales_Order_Transport_Boot
)
const (
Sales_Order_Relationtype_Organisation = iota + 1
Sales_Order_Relationtype_Private
)