Skip to content

Commit

Permalink
实现后端 sysinfo/hostname 接口
Browse files Browse the repository at this point in the history
  • Loading branch information
hpq committed Sep 4, 2018
1 parent 7d4561a commit f8ba34b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
11 changes: 11 additions & 0 deletions controllers/sysInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,15 @@ func (c *SysInfoController) GetSysInfo() {
handler := &sysInfo.AllInfo{Controller: &c.Controller}
c.Data["json"] = handler.Do()
c.ServeJSON()
}

// @Title Hostname
// @Description Get hostname reported by the kernel.
// @Success 200 {object} models.Object
// @Failure 403 :objectId is empty
// @router /hostname [get]
func (c *SysInfoController) GetHostname() {
handler := &sysInfo.Hostname{}
c.Data["json"] = handler.Do()
c.ServeJSON()
}
20 changes: 20 additions & 0 deletions controllers/sysInfo/hostname.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package sysInfo

import (
"fmt"
"os"
"github.com/astaxie/beego"
)

type Hostname struct {
Controller *beego.Controller
}

func (p *Hostname) Do() interface{} {
fmt.Println("hostname:", os.Hostname)
hostname, err := os.Hostname()
if err != nil {
return "unknown"
}
return hostname
}

0 comments on commit f8ba34b

Please sign in to comment.