Attr returns the value of an attribute on op. It returns an error if the attribute does not exist.
(name string)
| 36 | // Attr returns the value of an attribute on op. It returns an error if the |
| 37 | // attribute does not exist. |
| 38 | func (op *Operation) Attr(name string) (interface{}, error) { |
| 39 | cname := C.CString(name) |
| 40 | defer C.free(unsafe.Pointer(cname)) |
| 41 | |
| 42 | status := newStatus() |
| 43 | meta := C.TF_OperationGetAttrMetadata(op.c, cname, status.c) |
| 44 | if err := status.Err(); err != nil { |
| 45 | return nil, err |
| 46 | } |
| 47 | |
| 48 | if meta.is_list == 1 { |
| 49 | return listAttribute(op, cname, meta) |
| 50 | } |
| 51 | return scalarAttribute(op, cname, meta) |
| 52 | } |
| 53 | |
| 54 | func listAttribute(op *Operation, cname *C.char, meta C.TF_AttrMetadata) (interface{}, error) { |
| 55 | status := newStatus() |