如何在结构中插入数据

type Orders struct {
    data []struct {
        href    string `json:"href"`
        order_id string `json:"order_id"`
    } `json:"data"`
}

How do I insert data in to data array struct in orders struct?

orders.data = append(orders.data, orders.data{ href: r.Host+r.URL.Path+"/"+orderid, order_id: orderid})

it errors. What's wrong?

First see append built-in function.

orders.data is not a type. data is a field with an anonymous struct type of the struct named orders. So you should either name that anonymous struct to something like:

type HrefAndOrderID struct {
    href     string `json:"href"`
    order_id string `json:"order_id"`
}

And use

HrefAndOrderID{"dummy_href", "dummy_order_id"}

when appending.

Otherwise you can again use the same signature of that anonymous struct to append:

orders.data = append(orders.data, struct{href string `json:"href"`; order_id string `json:"order_id"`}{ href: r.Host+r.URL.Path+"/"+orderid, order_id: orderid})