Skip to content

Commit af9e62b

Browse files
committed
<WEB 框架修改>
1 parent a511676 commit af9e62b

File tree

1 file changed

+24
-29
lines changed

1 file changed

+24
-29
lines changed

main.go

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,52 @@
11
package main
22

33
import (
4-
"github.com/go-martini/martini"
4+
"gopkg.in/gin-gonic/gin.v1"
55
"github.com/shirou/gopsutil/mem"
66
"github.com/shirou/gopsutil/cpu"
77
"github.com/shirou/gopsutil/disk"
8-
"github.com/martini-contrib/render"
9-
"net/http"
108
)
119

12-
func init() {
13-
martini.Env = martini.Prod
14-
}
15-
1610
func main() {
17-
m := martini.Classic()
18-
m.Use(render.Renderer())
11+
gin.SetMode("release")
12+
r := gin.Default()
1913
//SWAP大小
20-
m.Get("/swap/info", func(r render.Render) {
14+
r.GET("/swap/info", func(c *gin.Context) {
2115
swap, _ := mem.SwapMemory()
22-
r.JSON(200, swap)
16+
c.JSON(200, swap)
2317
})
2418
//虚拟内存
25-
m.Get("/vmem/info", func(r render.Render) {
19+
r.GET("/vmem/info", func(c *gin.Context) {
2620
vmem, _ := mem.VirtualMemory()
27-
r.JSON(200, vmem)
28-
})
29-
//CPU 运行时情况
30-
m.Get("/cpu/time", func(r render.Render){
31-
cpuTime, _ := cpu.Times(true)
32-
r.JSON(200, cpuTime)
21+
c.JSON(200, vmem)
3322
})
23+
3424
//CPU 信息详细
35-
m.Get("/cpu/info",func(r render.Render){
25+
r.GET("/cpu/info", func(c *gin.Context) {
3626
cpuinfo, _ := cpu.Info()
37-
r.JSON(200, cpuinfo)
27+
c.JSON(200, cpuinfo)
28+
})
29+
30+
//CPU 运行时情况
31+
r.GET("/cpu/time", func(c *gin.Context) {
32+
cpuTime, _ := cpu.Times(true)
33+
c.JSON(200, cpuTime)
3834
})
3935
////硬盘列表 信息详细
40-
m.Get("/disk/list", func(r render.Render) {
36+
r.GET("/disk/list",func(c *gin.Context) {
4137
diskPart, _ := disk.Partitions(true)
42-
r.JSON(200, diskPart)
38+
c.JSON(200, diskPart)
4339
})
4440
//硬盘使用 信息详细
45-
m.Get("/disk/usage", func(r render.Render){
41+
r.GET("/disk/usage", func(c *gin.Context) {
4642
diskInfo, _ := disk.Usage("/")
47-
r.JSON(200, diskInfo)
43+
c.JSON(200, diskInfo)
4844
})
4945
//制定目录使用 信息详细
50-
m.Post("/disk/path", func(r render.Render, req *http.Request){
51-
path := req.FormValue("path")
46+
r.POST("/disk/path", func(c *gin.Context){
47+
path := c.PostForm("path")
5248
diskInfo, _ := disk.Usage(path)
53-
r.JSON(200, diskInfo)
49+
c.JSON(200, diskInfo)
5450
})
55-
//m.Run()
56-
m.RunOnAddr(":8848")
51+
r.Run(":8848") // listen and serve on 0.0.0.0:8080
5752
}

0 commit comments

Comments
 (0)