当前位置: 首页>>代码示例>>Golang>>正文


Golang Conn.RemoteAddr方法代码示例

本文整理汇总了Golang中tcpserver.Conn.RemoteAddr方法的典型用法代码示例。如果您正苦于以下问题:Golang Conn.RemoteAddr方法的具体用法?Golang Conn.RemoteAddr怎么用?Golang Conn.RemoteAddr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tcpserver.Conn的用法示例。


在下文中一共展示了Conn.RemoteAddr方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: HandlerMessage


//.........这里部分代码省略.........
		if err := json.Unmarshal(data[1:], &assest); err != nil {
			slog.Error("HandlerMessage() Parse ASSESTDISCOVERY error(%s), data(%s)", err.Error(), string(data[1:]))
			return
		}
		host, err := mysql.GetHostByUUID(assest.UUID)
		if err != nil {
			slog.Error("HandlerMessage() ASSESTDISCOVERY get host by uuid error(%s) assest(%v)", err.Error(), assest)
			return
		}
		//有资产信息
		if host.AssestId != 0 {
			oldassest := mysql.GetAssestByID(host.AssestId)
			flag := 0
			if oldassest.SN != assest.SN {
				oldassest.SN = assest.SN
				flag = 1
			}
			if oldassest.Vender != assest.Vender {
				oldassest.Vender = assest.Vender
				flag = 1
			}
			if oldassest.Model != assest.Model {
				oldassest.Model = assest.Model
				flag = 1
			}
			if flag == 1 {
				if err := mysql.UpdateAssest(oldassest); err != nil {
					slog.Error("update assest error(%s) assest(%v)", err.Error(), oldassest)
					return
				}
			}
			for _, cpu := range assest.Cpus {
				if c, ok := oldassest.Cpus[cpu.Name]; ok {
					cpu.ID = c.ID
					mysql.UpdateCpu(cpu)

				} else {
					mysql.CreateCpu(oldassest.ID, cpu)
				}

			}
			for _, disk := range assest.Disks {
				if d, ok := oldassest.Disks[disk.Slot]; ok {
					disk.ID = d.ID
					mysql.UpdateDisk(disk)
				} else {
					mysql.CreateDisk(oldassest.ID, disk)
				}

			}
			for _, nic := range assest.Nics {
				if n, ok := oldassest.Nics[nic.Name]; ok {
					nic.ID = n.ID
					mysql.UpdateNic(nic)
				} else {
					mysql.CreateNic(oldassest.ID, nic)
				}

			}
			for _, memory := range assest.Memorys {
				if m, ok := oldassest.Memorys[memory.Locator]; ok {
					memory.ID = m.ID
					mysql.UpdateMemory(memory)
				} else {
					mysql.CreateMemory(oldassest.ID, memory)
				}
			}
			return
		}
		//创建资产
		id, err := mysql.CreateAssest(assest)
		if err != nil {
			slog.Error("add assest error(%s) assest(%v)", err.Error(), assest)
			return
		}
		if err := mysql.UpdateHostAssest(host.ID, id); err != nil {
			slog.Error("linked host and assest error (%s) host(%v) assest(%v)", err.Error(), host, assest)
			return
		}
		slog.Info("add assest done, assest(%v)", assest)
	case HOSTHB:
		p := HeartBeat{}
		if err := json.Unmarshal(data[1:], &p); err != nil {
			slog.Error("HandlerMessage() Parse HOSTHB error(%s), data(%s)", err.Error(), string(data[1:]))
			return
		}
		host, err := mysql.GetHostByUUID(p.UUID)
		if err != nil {
			slog.Error("HandlerMessage() GetHostByUUID() error message(%s)", err.Error())
			return
		}
		if err := mysql.UpdateHostLastCheck(host); err != nil {
			slog.Error("update host last_check eror host(%v) error(%s)", host, err.Error())
		} else {
			slog.Info("update host last_check, host(%s:%s)", host.UUID, host.Ip)
		}
	default:
		slog.Warn("unknown protocol type, ip:%s,  data %s", conn.RemoteAddr(), string(data))
	}
}
开发者ID:y8y,项目名称:OWL-v3,代码行数:101,代码来源:handle.go

示例2: Disconnect

func (this *handle) Disconnect(conn *tcpserver.Conn) {
	slog.Info("%s disconnect ", conn.RemoteAddr())
}
开发者ID:y8y,项目名称:OWL-v3,代码行数:3,代码来源:handle.go

示例3: Connect

func (this *handle) Connect(conn *tcpserver.Conn) {
	log.Info("%s connected", conn.RemoteAddr())
}
开发者ID:y8y,项目名称:OWL-v3,代码行数:3,代码来源:handle.go


注:本文中的tcpserver.Conn.RemoteAddr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。