From f8ba34b14e46aa4fbc9c92873bfcfe149c37be02 Mon Sep 17 00:00:00 2001 From: hpq Date: Tue, 4 Sep 2018 14:49:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=90=8E=E7=AB=AF=20sysinfo/?= =?UTF-8?q?hostname=20=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/sysInfo.go | 11 +++++++++++ controllers/sysInfo/hostname.go | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100755 controllers/sysInfo/hostname.go diff --git a/controllers/sysInfo.go b/controllers/sysInfo.go index 1d5f33e..3353d08 100755 --- a/controllers/sysInfo.go +++ b/controllers/sysInfo.go @@ -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() } \ No newline at end of file diff --git a/controllers/sysInfo/hostname.go b/controllers/sysInfo/hostname.go new file mode 100755 index 0000000..5593174 --- /dev/null +++ b/controllers/sysInfo/hostname.go @@ -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 +} \ No newline at end of file