Skip to content

Commit 9b275f0

Browse files
committed
add md devices
1 parent 776cf00 commit 9b275f0

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed

api/devices.go

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package api
2+
3+
type DevicesCables struct {
4+
ResponseMessage
5+
Devices []DeviceCable
6+
}
7+
8+
type DevicesWifis struct {
9+
ResponseMessage
10+
Devices []DeviceWifi
11+
}
12+
13+
type Device struct {
14+
Platform string `json:"platform"`
15+
TotalSpeed int `json:"total_speed"`
16+
Down string `json:"down"`
17+
DownSpeed int `json:"down_speed"`
18+
DownLimit int `json:"down_limit"`
19+
Up string `json:"up"`
20+
UpSpeed int `json:"up_speed"`
21+
UpLimit int `json:"up_limit"`
22+
Hostname string `json:"host_name"`
23+
Type int `json:"type"`
24+
IP string `json:"ip"`
25+
MAC string `json:"mac"`
26+
LeftTime int `json:"leftTime"`
27+
Time int `json:"time"`
28+
Tag string `json:"tag"`
29+
Local int `json:"local"`
30+
ConnType int `json:"conn_type"`
31+
}
32+
33+
type DeviceCable struct {
34+
Device
35+
}
36+
37+
type DeviceWifi struct {
38+
Device
39+
Single int `json:"single"`
40+
RSSI0 int `json:"rssi0"`
41+
RSSI1 int `json:"rssi1"`
42+
RSSI2 int `json:"rssi2"`
43+
}
44+
45+
type DeviceDisk struct {
46+
ResponseMessage
47+
TotalSize int `json:"totalSize"`
48+
Left float32 `json:"left"`
49+
Name string `json:"name"`
50+
Time int `json:"time"`
51+
}

devices.go

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/codegangsta/cli"
7+
"github.com/modouwifi/md/api"
8+
)
9+
10+
var cmdDevices = cli.Command{
11+
Name: "devices",
12+
Usage: "Show Devices Info",
13+
Subcommands: []cli.Command{
14+
{
15+
Name: "cables",
16+
Usage: "Show cables info",
17+
Action: runDevicesCables,
18+
},
19+
{
20+
Name: "wifis",
21+
Usage: "Show wifis info",
22+
Action: runDevicesWifis,
23+
},
24+
{
25+
Name: "disk",
26+
Usage: "Show disk info",
27+
Action: runDevicesDisk,
28+
},
29+
},
30+
}
31+
32+
func runDevicesCables(c *cli.Context) {
33+
req, err := client.NewRequest("GET", "/devices/cables")
34+
if err != nil {
35+
fmt.Println(err)
36+
}
37+
req.SetCookie(config.Cookie)
38+
var result api.DevicesCables
39+
err = req.ToJSON(&result)
40+
fmt.Println(result)
41+
}
42+
43+
func runDevicesWifis(c *cli.Context) {
44+
req, err := client.NewRequest("GET", "/devices/wifis")
45+
if err != nil {
46+
fmt.Println(err)
47+
}
48+
req.SetCookie(config.Cookie)
49+
var result api.DevicesWifis
50+
err = req.ToJSON(&result)
51+
fmt.Println(result)
52+
}
53+
54+
func runDevicesDisk(c *cli.Context) {
55+
req, err := client.NewRequest("GET", "/devices/disk")
56+
if err != nil {
57+
fmt.Println(err)
58+
}
59+
req.SetCookie(config.Cookie)
60+
var result api.DeviceDisk
61+
err = req.ToJSON(&result)
62+
fmt.Println(result)
63+
}

main.go

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func init() {
5252
cmdWan,
5353
cmdWifi,
5454
cmdLan,
55+
cmdDevices,
5556
)
5657
}
5758

0 commit comments

Comments
 (0)