Gogland使用

Go语言也支持面向对象开发,不过和以往我们所使用的面向对象开发还是有不同,Go语言主张组合方式形成类的概念,在Go语言中,结构起到很大作用,如果用结构组合字段和方法,那么单纯在源代码中看,真的是费时费力,尤其看别人写的代码,举例如下:

type rawConnection struct {
	id       DeviceID
	name     string
	receiver Model

	cr *countingReader
	cw *countingWriter

	awaiting    map[int32]chan asyncResult
	awaitingMut sync.Mutex

	idxMut sync.Mutex // ensures serialization of Index calls

	nextID    int32
	nextIDMut sync.Mutex

	outbox      chan asyncMessage
	closed      chan struct{}
	once        sync.Once
	pool        bufferPool
	compression Compression
}

这个rawConnection是一个结构,同时它也定义了很多方法,如果仅仅在源代码里面查看,真的让你晕头转向,我刚才看rawConnection时候,看了半天,也没能完整了解它,但是,当我打开Gogland的“Structure”时候,真的不得不表扬Gogland,做得太棒了,立即完整展现了rawConnection,包括它所有的字段和方法,让我能够快速完整了解rawConnection!!Gogland默认情况下,“Structure”好像并没有打开,如果没有打开,我们可以点击顶部菜单打开:“View”->"Tools Windows"->"Structure",也可以通过快捷键“Alt+7”打开。

通过“Structure”查看rawConnection的整体结构,这个结构的全貌一览无遗,太棒了!!

原文地址:https://www.cnblogs.com/sunylat/p/6366373.html