本文譯自5 Tips To Speed Up Golang Development With IntelliJ Or Goland 確實很實用.golang
好比我想爲下面的結構體實現共識interface編程
type MyConensus struct { }
經過右鍵generate->implement methods->搜索engine
一鍵生成下面代碼:單元測試
type MyConensus struct { info string } func (m *MyConensus) Author(header *types.Header) (common.Address, error) { panic("implement me") } func (m *MyConensus) VerifyHeader(chain ChainReader, header *types.Header, seal bool) error { panic("implement me") } func (m *MyConensus) VerifyHeaders(chain ChainReader, headers []*types.Header, seals []bool) (chan<- struct{}, <-chan error) { panic("implement me") } func (m *MyConensus) VerifyUncles(chain ChainReader, block *types.Block) error { panic("implement me") } func (m *MyConensus) VerifySeal(chain ChainReader, header *types.Header) error { panic("implement me") } func (m *MyConensus) Prepare(chain ChainReader, header *types.Header) error { panic("implement me") } func (m *MyConensus) Finalize(chain ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error) { panic("implement me") } func (m *MyConensus) Seal(chain ChainReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}) error { panic("implement me") } func (m *MyConensus) SealHash(header *types.Header) common.Hash { panic("implement me") } func (m *MyConensus) CalcDifficulty(chain ChainReader, time uint64, parent *types.Header) *big.Int { panic("implement me") } func (m *MyConensus) APIs(chain ChainReader) []rpc.API { panic("implement me") } func (m *MyConensus) Close() error { panic("implement me") }
面向接口編程,有時候咱們須要針對已經實現的struct提取接口.
方法:
struct->Refactor->Extract->interfac
測試
forr 而後tab,就會自動展開ui
for key, value := range collection { }
err 而後tab,自動展開以下:
3d
這個相對不是很實用,
code
這個很是使用,單元測試,咱們專一於測試自己就ok了.
在文件任意位置->Genreate->Test for File-> 自動生成該文件對應的測試文件
blog