1. Implement interface
For example, I want to implement a common interface for the following structures
type MyConensus struct { }
Right click generate - > implementation methods - > search engine
One click to generate the following code:
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") }
Extract interface
Interface oriented programming, sometimes we need to extract the interface for the already implemented struct
Method:
struct->Refactor->Extract->interfac
2. Use template
3.1 forr rapid expansion for range
forr then tab, it will expand automatically
for key, value := range collection { }
3.2 err error handling
err then tab, automatically expand as follows:
4. Fill in Struct
This is not very practical,
5. Generate test code automatically
This is very useful, unit testing, we focus on the test itself is ok
Automatically generate the test file corresponding to the file anywhere - > generate - > test for file