diff --git a/README.md b/README.md index e1ceb1c58..cb96e95c6 100644 --- a/README.md +++ b/README.md @@ -237,6 +237,13 @@ func RestoreStdout() (s string) func RewriteStdout() ``` +## Code Check + +```bash +gofmt -w -l ./ +golint ./... +``` + ## License [MIT](LICENSE) diff --git a/cliutil/cliutil_test.go b/cliutil/cliutil_test.go index bb4596ccd..6bfb35f5a 100644 --- a/cliutil/cliutil_test.go +++ b/cliutil/cliutil_test.go @@ -1,3 +1 @@ package cliutil - - diff --git a/dump/dump.go b/dump/dump.go index 87145af78..09eccfc0b 100644 --- a/dump/dump.go +++ b/dump/dump.go @@ -23,14 +23,14 @@ type dumpConfig struct { // Config dump data settings var Config = dumpConfig{ ShowMethod: true, - MoreLenNL: 8, + MoreLenNL: 8, } // ResetConfig reset config data func ResetConfig() { Config = dumpConfig{ ShowMethod: true, - MoreLenNL: 8, + MoreLenNL: 8, } } diff --git a/fmtutil/format_test.go b/fmtutil/format_test.go index 78c4becac..216483e94 100644 --- a/fmtutil/format_test.go +++ b/fmtutil/format_test.go @@ -50,4 +50,4 @@ func TestStringsToInts(t *testing.T) { _, err = fmtutil.StringsToInts([]string{"a", "b"}) is.Error(err) -} \ No newline at end of file +} diff --git a/mathutil/convert.go b/mathutil/convert.go index 9a6563c7b..b195e3c78 100644 --- a/mathutil/convert.go +++ b/mathutil/convert.go @@ -7,7 +7,7 @@ import ( ) var ( - errConvertFail = errors.New("convert data type is failure") + errConvertFail = errors.New("convert data type is failure") ) /************************************************************* diff --git a/strutil/encode.go b/strutil/encode.go index d7f54e1d2..ed2cbe250 100644 --- a/strutil/encode.go +++ b/strutil/encode.go @@ -11,8 +11,9 @@ import ( ) var ( - // escape string. + // EscapeJS escape javascript string EscapeJS = template.JSEscapeString + // EscapeHTML escape html string EscapeHTML = template.HTMLEscapeString ) @@ -59,4 +60,3 @@ func URLDecode(s string) string { return s } - diff --git a/strutil/encode_test.go b/strutil/encode_test.go index 810fdbecd..678f74a8e 100644 --- a/strutil/encode_test.go +++ b/strutil/encode_test.go @@ -7,17 +7,17 @@ import ( "github.com/stretchr/testify/assert" ) -func TestEscape(t *testing.T) { - tests := struct {give, want string} { +func TestEscape(t *testing.T) { + tests := struct{ give, want string }{ "
some text
", "<p>some text</p>", } assert.Equal(t, tests.want, strutil.EscapeHTML(tests.give)) - tests = struct {give, want string} { - "", - `\x3Cscript\x3Evar a = 23;\x3C/script\x3E`, + tests = struct{ give, want string }{ + "", + `\x3Cscript\x3Evar a = 23;\x3C/script\x3E`, } assert.Equal(t, tests.want, strutil.EscapeJS(tests.give)) } diff --git a/strutil/format.go b/strutil/format.go index afd732150..681ed2966 100644 --- a/strutil/format.go +++ b/strutil/format.go @@ -117,4 +117,3 @@ func CamelCase(s string, sep ...string) string { return UpperFirst(s) }) } - diff --git a/strutil/format_test.go b/strutil/format_test.go index 4359c1112..663d7d561 100644 --- a/strutil/format_test.go +++ b/strutil/format_test.go @@ -88,4 +88,4 @@ func TestCamelCase(t *testing.T) { // custom sep char is.Equal("rangePrice", strutil.CamelCase("range+price", "+")) is.Equal("rangePrice", strutil.CamelCase("range*price", "*")) -} \ No newline at end of file +} diff --git a/strutil/strutil.go b/strutil/strutil.go index dec0b3d3f..a950b84c0 100644 --- a/strutil/strutil.go +++ b/strutil/strutil.go @@ -8,6 +8,7 @@ import ( "text/template" ) +// Position for padding string const ( PosLeft uint8 = iota PosRight @@ -123,7 +124,7 @@ func PadRight(s, pad string, length int) string { // Repeat repeat a string func Repeat(s string, times int) string { if times < 2 { - return s + return s } var ss []string diff --git a/strutil/strutil_test.go b/strutil/strutil_test.go index 8bad8524f..9c5756672 100644 --- a/strutil/strutil_test.go +++ b/strutil/strutil_test.go @@ -78,11 +78,11 @@ func TestRepeat(t *testing.T) { } func TestPadding(t *testing.T) { - tests := []struct{ + tests := []struct { want, give, pad string - len int - pos uint8 - } { + len int + pos uint8 + }{ {"ab000", "ab", "0", 5, strutil.PosRight}, {"000ab", "ab", "0", 5, strutil.PosLeft}, }