|
| 1 | +package box |
| 2 | + |
| 3 | +import "github.com/tarantool/go-tarantool/v2" |
| 4 | + |
| 5 | +// ClusterInfo represents information about the cluster. |
| 6 | +// It contains the unique identifier (UUID) of the cluster. |
| 7 | +type ClusterInfo struct { |
| 8 | + UUID string `msgpack:"uuid"` |
| 9 | +} |
| 10 | + |
| 11 | +// Info represents detailed information about the Tarantool instance. |
| 12 | +// It includes version, node ID, read-only status, process ID, cluster information, and more. |
| 13 | +type Info struct { |
| 14 | + // The Version of the Tarantool instance. |
| 15 | + Version string `msgpack:"version"` |
| 16 | + // The node ID (nullable). |
| 17 | + ID *int `msgpack:"id"` |
| 18 | + // Read-only (RO) status of the instance. |
| 19 | + RO bool `msgpack:"ro"` |
| 20 | + // UUID - Unique identifier of the instance. |
| 21 | + UUID string `msgpack:"uuid"` |
| 22 | + // Process ID of the instance. |
| 23 | + PID int `msgpack:"pid"` |
| 24 | + // Status - Current status of the instance (e.g., running, unconfigured). |
| 25 | + Status string `msgpack:"status"` |
| 26 | + // LSN - Log sequence number of the instance. |
| 27 | + LSN uint64 `msgpack:"lsn"` |
| 28 | + // Cluster information, including cluster UUID. |
| 29 | + Cluster ClusterInfo `msgpack:"cluster"` |
| 30 | +} |
| 31 | + |
| 32 | +// Info retrieves the current information of the Tarantool instance. |
| 33 | +// It calls the "box.info" function and parses the result into the Info structure. |
| 34 | +func (b *box) Info() (Info, error) { |
| 35 | + var info Info |
| 36 | + |
| 37 | + // Call "box.info" to get instance information from Tarantool. |
| 38 | + fut := b.conn.Do(tarantool.NewCallRequest("box.info")) |
| 39 | + |
| 40 | + // Parse the result into the Info structure. |
| 41 | + err := fut.GetTyped(&[]interface{}{&info}) |
| 42 | + if err != nil { |
| 43 | + return Info{}, err |
| 44 | + } |
| 45 | + |
| 46 | + // Return the parsed info and any potential error. |
| 47 | + return info, err |
| 48 | +} |
0 commit comments