diff --git a/pkg/assert/assert.go b/pkg/assert/assert.go index b054962..3a800e4 100644 --- a/pkg/assert/assert.go +++ b/pkg/assert/assert.go @@ -7,17 +7,16 @@ // Author: Chef (191201771@qq.com) // Package assert 提供了单元测试时的断言功能,减少一些模板代码 -// package assert import "github.com/q191201771/naza/pkg/nazareflect" // TestingT 单元测试中的 *testing.T 和 *testing.B 都满足该接口 -// type TestingT interface { Errorf(format string, args ...interface{}) } +// TODO(chef): [refactor] 考虑将Helper方法移入 TestingT 202211 type tHelper interface { Helper() } @@ -33,7 +32,6 @@ func Equal(t TestingT, expected interface{}, actual interface{}, msg ...string) } // IsNotNil 比如有时我们需要对 error 类型不等于 nil 做断言,但是我们并不关心 error 的具体值是什么 -// func IsNotNil(t TestingT, actual interface{}, msg ...string) { if h, ok := t.(tHelper); ok { h.Helper() diff --git a/pkg/bele/bele.go b/pkg/bele/bele.go index 1fdf8b5..cfc2846 100644 --- a/pkg/bele/bele.go +++ b/pkg/bele/bele.go @@ -12,7 +12,6 @@ // le是little endian的缩写,即小端 // // assume local is `le` -// package bele import ( @@ -124,6 +123,7 @@ func ReadLeUint16(r io.Reader) (uint16, error) { } return LeUint16(b), nil } + // ----- 序列化 ----- func BePutUint16(out []byte, in uint16) { diff --git a/pkg/bele/bele_test.go b/pkg/bele/bele_test.go index fb3e7e6..3ba6d0e 100644 --- a/pkg/bele/bele_test.go +++ b/pkg/bele/bele_test.go @@ -121,8 +121,8 @@ func TestLeUint16(t *testing.T) { output uint16 }{ {input: []byte{0, 0}, output: 0}, - {input: []byte{0, 1}, output: 1* 256 }, - {input: []byte{1, 0}, output: 1 }, + {input: []byte{0, 1}, output: 1 * 256}, + {input: []byte{1, 0}, output: 1}, {input: []byte{12, 34}, output: 12 + 34*256}, {input: []byte{1, 99}, output: 1 + 99*256}, } @@ -207,7 +207,7 @@ func TestLePutUint16(t *testing.T) { {input: 0, output: []byte{0, 0}}, {input: 1 * 256, output: []byte{0, 1}}, {input: 1, output: []byte{1, 0}}, - {input: 34*256 + 12, output: []byte{12, 34}}, + {input: 34*256 + 12, output: []byte{12, 34}}, } out := make([]byte, 2) diff --git a/pkg/bininfo/bininfo.go b/pkg/bininfo/bininfo.go index 53e9c9f..7137f48 100644 --- a/pkg/bininfo/bininfo.go +++ b/pkg/bininfo/bininfo.go @@ -10,7 +10,6 @@ // // 将编译时源码的git版本信息(当前tag,commit log的sha值和commit message,是否有未提交的修改),编译时间,Go版本,编译、运行平台打入程序中 // 编译时传入这些信息的方式见 naza 的编译脚本: https://github.com/q191201771/naza/blob/master/build.sh -// package bininfo import ( diff --git a/pkg/bitrate/bitrate.go b/pkg/bitrate/bitrate.go index 153976c..bcf2ffe 100644 --- a/pkg/bitrate/bitrate.go +++ b/pkg/bitrate/bitrate.go @@ -7,7 +7,6 @@ // Author: Chef (191201771@qq.com) // Package bitrate 平滑计算比特率(码率) -// package bitrate import ( diff --git a/pkg/chartbar/chartbar.go b/pkg/chartbar/chartbar.go index faff391..430461d 100644 --- a/pkg/chartbar/chartbar.go +++ b/pkg/chartbar/chartbar.go @@ -7,7 +7,6 @@ // Author: Chef (191201771@qq.com) // Package chartbar 控制台绘制ascii柱状图 -// package chartbar const ( @@ -74,7 +73,6 @@ func NewCtx(modOptions ...ModOption) *Ctx { // NewCtxWith // // 在`ctx`参数基础上使用`modOptions`生成新的 Ctx -// func NewCtxWith(ctx *Ctx, modOptions ...ModOption) *Ctx { option := ctx.option for _, fn := range modOptions { diff --git a/pkg/chartbar/ctx.go b/pkg/chartbar/ctx.go index f88bf39..9470442 100644 --- a/pkg/chartbar/ctx.go +++ b/pkg/chartbar/ctx.go @@ -27,7 +27,6 @@ type Ctx struct { // WithItems // // @param items: 注意,内部不会修改切片底层数据的值以及顺序 -// func (ctx *Ctx) WithItems(items []Item) string { // 拷贝一份,避免修改外部切片的原始顺序 if ctx.option.Order != OrderOrigin { diff --git a/pkg/consistenthash/consistenthash.go b/pkg/consistenthash/consistenthash.go index 84f5dac..8304777 100644 --- a/pkg/consistenthash/consistenthash.go +++ b/pkg/consistenthash/consistenthash.go @@ -45,16 +45,17 @@ type ModOption func(option *Option) // @param dups: 每个实际的 node 转变成多少个环上的节点,必须大于等于1 // @param modOptions: 可修改内部的哈希函数,比如替换成murmur32的开源实现,可以这样: -// import "github.com/spaolacci/murmur3" -// import "github.com/q191201771/naza/pkg/consistenthash" // -// ch := consistenthash.New(1000, func(option *Option) { -// option.hfn = func(bytes []byte) uint32 { -// h := murmur3.New32() -// h.Write(bytes) -// return h.Sum32() -// } -// }) +// import "github.com/spaolacci/murmur3" +// import "github.com/q191201771/naza/pkg/consistenthash" +// +// ch := consistenthash.New(1000, func(option *Option) { +// option.hfn = func(bytes []byte) uint32 { +// h := murmur3.New32() +// h.Write(bytes) +// return h.Sum32() +// } +// }) func New(dups int, modOptions ...ModOption) ConsistentHash { option := defaultOption for _, fn := range modOptions { diff --git a/pkg/crypto/aes_cbc.go b/pkg/crypto/aes_cbc.go index 698ea01..f4d6802 100644 --- a/pkg/crypto/aes_cbc.go +++ b/pkg/crypto/aes_cbc.go @@ -18,8 +18,9 @@ import ( var CommonIv = []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f} // @param key 16字节 -> AES128 -// 24字节 -> AES192 -// 32字节 -> AES256 +// +// 24字节 -> AES192 +// 32字节 -> AES256 func EncryptAesWithCbc(in []byte, key []byte, iv []byte) ([]byte, error) { block, err := aes.NewCipher(key) if err != nil { diff --git a/pkg/crypto/pkcs.go b/pkg/crypto/pkcs.go index 0f16f18..6453790 100644 --- a/pkg/crypto/pkcs.go +++ b/pkg/crypto/pkcs.go @@ -16,7 +16,8 @@ import ( var ErrPkcs = errors.New("naza.crypto: fxxk") // @param blockSize 取值范围[0, 255] -// 如果是AES,见标准库中aes.BlockSize等于16 +// +// 如果是AES,见标准库中aes.BlockSize等于16 func EncryptPkcs7(in []byte, blockSize int) []byte { paddingLength := blockSize - len(in)%blockSize paddingBuf := bytes.Repeat([]byte{byte(paddingLength)}, paddingLength) diff --git a/pkg/dataops/dataops.go b/pkg/dataops/dataops.go index 3979a89..4b6fbfd 100644 --- a/pkg/dataops/dataops.go +++ b/pkg/dataops/dataops.go @@ -19,7 +19,6 @@ import ( // @param fn: 业务方编写转换逻辑,内部对原始切片的元素逐个回调给业务方,并通过回调返回值组成转换后的字符串切片 // // @return ret: 转换后的字符串切片 -// func Slice2Strings(a interface{}, fn func(originItem interface{}) string) (ret []string) { IterateInterfaceAsSlice(a, func(iterItem interface{}) bool { ret = append(ret, fn(iterItem)) @@ -29,7 +28,6 @@ func Slice2Strings(a interface{}, fn func(originItem interface{}) string) (ret [ } // Slice2Times 将任意类型切片转换为时间切片 -// func Slice2Times(a interface{}, fn func(originItem interface{}) time.Time) (ret []time.Time) { IterateInterfaceAsSlice(a, func(iterItem interface{}) bool { ret = append(ret, fn(iterItem)) @@ -41,7 +39,6 @@ func Slice2Times(a interface{}, fn func(originItem interface{}) time.Time) (ret // --------------------------------------------------------------------------------------------------------------------- // SliceUniqueCount 遍历切片`a`,逐个调用`fn`转换为string, 并将所有元素归类计数 -// func SliceUniqueCount(a interface{}, fn func(originItem interface{}) string) (ret map[string]int) { ret = make(map[string]int) IterateInterfaceAsSlice(a, func(iterItem interface{}) bool { @@ -55,9 +52,9 @@ func SliceUniqueCount(a interface{}, fn func(originItem interface{}) string) (re // --------------------------------------------------------------------------------------------------------------------- // SliceLimit 取切片前`PrefixNumLimit`个元素和后`SuffixNumLimit`个元素,通过`cb`回调给业务方 -// 注意,内部会处理`PrefixNumLimit`或`SuffixNumLimit`过大的情况 -// `PrefixNumLimit`如果为-1,则没有限制,`SuffixNumLimit`同理 // +// 注意,内部会处理`PrefixNumLimit`或`SuffixNumLimit`过大的情况 +// `PrefixNumLimit`如果为-1,则没有限制,`SuffixNumLimit`同理 func SliceLimit(a interface{}, PrefixNumLimit int, SuffixNumLimit int, cb func(index int)) { v := reflect.ValueOf(a) if PrefixNumLimit == -1 && SuffixNumLimit == -1 { @@ -108,8 +105,8 @@ func Map2Strings(a interface{}, fn func(k, v interface{}) string) (ret []string) // 遍历切片`a`,通过`onIterate`逐个回调元素 // // @param onIterate: -// @return keepIterate: 如果返回false,则停止变化 // +// @return keepIterate: 如果返回false,则停止变化 func IterateInterfaceAsSlice(a interface{}, onIterate func(iterItem interface{}) (keepIterate bool)) { // TODO(chef): fix haven't use keepIterate v := reflect.ValueOf(a) diff --git a/pkg/filebatch/filebatch_test.go b/pkg/filebatch/filebatch_test.go index 7991a2b..12a812b 100644 --- a/pkg/filebatch/filebatch_test.go +++ b/pkg/filebatch/filebatch_test.go @@ -36,16 +36,17 @@ var tail = ` ` // // -// |-- /dir1/ -// |-- /dir2/ -// |-- file5 -// |-- file6 -// |-- file7.txt -// |-- file8.txt -// |-- file1 -// |-- file2 -// |-- file3.txt -// |-- file4.txt +// +// |-- /dir1/ +// |-- /dir2/ +// |-- file5 +// |-- file6 +// |-- file7.txt +// |-- file8.txt +// |-- file1 +// |-- file2 +// |-- file3.txt +// |-- file4.txt func prepareTestFile() (string, error) { filenameToContent = make(map[string][]byte) diff --git a/pkg/nazaatomic/atomic_32bit.go b/pkg/nazaatomic/atomic_32bit.go index a71225a..e693cf4 100644 --- a/pkg/nazaatomic/atomic_32bit.go +++ b/pkg/nazaatomic/atomic_32bit.go @@ -6,6 +6,7 @@ // // Author: Chef (191201771@qq.com) +//go:build 386 || arm || mips || mipsle // +build 386 arm mips mipsle package nazaatomic diff --git a/pkg/nazaatomic/atomic_64bit.go b/pkg/nazaatomic/atomic_64bit.go index 9dc555d..9ff1f12 100644 --- a/pkg/nazaatomic/atomic_64bit.go +++ b/pkg/nazaatomic/atomic_64bit.go @@ -6,6 +6,7 @@ // // Author: Chef (191201771@qq.com) +//go:build !386 && !arm && !mips && !mipsle // +build !386,!arm,!mips,!mipsle package nazaatomic diff --git a/pkg/nazabits/bits.go b/pkg/nazabits/bits.go index 719bdc3..eb810f2 100644 --- a/pkg/nazabits/bits.go +++ b/pkg/nazabits/bits.go @@ -160,7 +160,6 @@ func (br *BitReader) ReadGolomb() (v uint32, err error) { } // ReadUeGolomb 0阶指数哥伦布编码,无符号 -// func (br *BitReader) ReadUeGolomb() (v uint32, err error) { var t uint8 var n uint @@ -185,7 +184,6 @@ func (br *BitReader) ReadUeGolomb() (v uint32, err error) { } // ReadSeGolomb 哥伦布编码,有符号 -// func (br *BitReader) ReadSeGolomb() (v int32, err error) { var vv uint32 vv, err = br.ReadUeGolomb() @@ -324,10 +322,12 @@ func GetBit8(v uint8, pos uint) uint8 { // @param n: 取多少位, 取值范围 [1, 8] // // 举例,GetBits8(105, 2, 4) = 10(即1010) -// v: 0110 1001 +// +// v: 0110 1001 +// // pos: 2 -// n: .. .. // +// n: .. .. func GetBits8(v uint8, pos uint, n uint) uint8 { return v >> pos & m1[n] } diff --git a/pkg/nazacolor/color.go b/pkg/nazacolor/color.go index ce19892..79db669 100644 --- a/pkg/nazacolor/color.go +++ b/pkg/nazacolor/color.go @@ -24,7 +24,6 @@ import "fmt" // Format 格式 // // TODO(chef): 添加其他值:0(默认值)、1(高亮)、22(非粗体)、4(下划线)、24(非下划线)、 5(闪烁)、25(非闪烁)、7(反显)、27(非反显) -// type Format int const ( @@ -32,7 +31,6 @@ const ( ) // FgColor 前景色(字体颜色) -// type FgColor int const ( @@ -48,7 +46,6 @@ const ( ) // BgColor 背景色 -// type BgColor int const ( @@ -81,25 +78,21 @@ const ( ) // Wrap 分别设置样式,前景色(字体颜色),背景色 -// func Wrap(v string, format Format, fg FgColor, bg BgColor) string { return fmt.Sprintf("%s%d;%d;%dm%s%s", prefix, format, fg, bg, v, suffix) } // WrapWithFgColor 只设置前景色(字体颜色) -// func WrapWithFgColor(v string, fg FgColor) string { return fmt.Sprintf("%s%d;%dm%s%s", prefix, FormatNonBold, fg, v, suffix) } // WrapBlack 将前景色(字体颜色)设置为黑色 -// func WrapBlack(v string) string { return WrapWithFgColor(v, FgBlack) } // WrapRed 将前景色(字体颜色)设置为红色 -// func WrapRed(v string) string { return WrapWithFgColor(v, FgRed) } diff --git a/pkg/nazaerrors/wrap113.go b/pkg/nazaerrors/wrap113.go index b413bdb..eea4821 100644 --- a/pkg/nazaerrors/wrap113.go +++ b/pkg/nazaerrors/wrap113.go @@ -6,6 +6,7 @@ // // Author: Chef (191201771@qq.com) +//go:build go1.13 // +build go1.13 package nazaerrors diff --git a/pkg/nazaerrors/wrap113_test.go b/pkg/nazaerrors/wrap113_test.go index fcd5a4a..7fb830b 100644 --- a/pkg/nazaerrors/wrap113_test.go +++ b/pkg/nazaerrors/wrap113_test.go @@ -6,6 +6,7 @@ // // Author: Chef (191201771@qq.com) +//go:build go1.13 // +build go1.13 package nazaerrors diff --git a/pkg/nazamd5/md5.go b/pkg/nazamd5/md5.go index 1a3eec4..d373424 100644 --- a/pkg/nazamd5/md5.go +++ b/pkg/nazamd5/md5.go @@ -16,7 +16,6 @@ import ( // Md5 返回32字节小写字符串 // // TODO(chef): [refactor] 重命名为Md5sum -// func Md5(b []byte) string { h := md5.New() h.Write(b)