You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.1 KiB
Go
58 lines
1.1 KiB
Go
package controllers
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/astaxie/beego"
|
|
"github.com/astaxie/beego/logs"
|
|
"goftp/service"
|
|
)
|
|
|
|
type IpController struct {
|
|
beego.Controller
|
|
}
|
|
|
|
type IpPort struct {
|
|
Ret string `json:"ret"`
|
|
Ip string `json:"ip"`
|
|
Data []string `json:"data"`
|
|
}
|
|
|
|
// @Title GetIp
|
|
// @Description 获取 发起http请求客户端 的公网ip
|
|
// @router /getIp [get]
|
|
func (c *IpController) GetIp() {
|
|
req := c.Ctx.Request
|
|
ddr := req.RemoteAddr // "IP:port" "192.168.1.150:8889"
|
|
logs.Debug(ddr)
|
|
ipPort := new(IpPort)
|
|
ips := strings.Split(ddr, ":")
|
|
if len(ips) > 0 {
|
|
ipPort.Ip = ips[0]
|
|
}
|
|
ipPort.Data = make([]string, 0)
|
|
ipPort.Ret = "ok"
|
|
c.Data["json"] = ipPort
|
|
logs.Debug(*ipPort)
|
|
c.ServeJSON()
|
|
}
|
|
|
|
// @Title GetHomeIp
|
|
// @Description 上传文件
|
|
// @Param id query int true "根据cm_ip表的id 查询公网ip"
|
|
// @router /getHomeIp [get]
|
|
func (c *IpController) GetHomeIp() {
|
|
id := c.Ctx.Input.Query("id")
|
|
if id == "" {
|
|
id = "1"
|
|
}
|
|
ip := service.GetIpById(id)
|
|
ipPort := new(IpPort)
|
|
ipPort.Data = make([]string, 0)
|
|
ipPort.Ret = "ok"
|
|
ipPort.Ip = ip
|
|
c.Data["json"] = ipPort
|
|
logs.Debug(*ipPort)
|
|
c.ServeJSON()
|
|
}
|