随笔 - 217  文章 - 1  评论 - 48  阅读 - 64万

五个goland进行go开发的小技巧

五个goland进行go开发的小技巧

本文译自5 Tips To Speed Up Golang Development With IntelliJ Or Goland 确实很实用.

1. 实现interface

比如我想为下面的结构体实现共识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

2. 使用模板

3.1 forr 快速展开for range

forr 然后tab,就会自动展开

	for key, value := range collection {
		
	}

3.2 err 错误处理

err 然后tab,自动展开如下:

4. 填充Struct

这个相对不是很实用,

5. 自动生成测试代码

这个非常使用,单元测试,我们专注于测试本身就ok了.
在文件任意位置->Genreate->Test for File-> 自动生成该文件对应的测试文件

posted on   baizx  阅读(8316)  评论(3编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 写一个简单的SQL生成工具
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示