diff options
| author | Shulhan <m.shulhan@gmail.com> | 2020-05-16 19:52:33 +0700 |
|---|---|---|
| committer | Shulhan <m.shulhan@gmail.com> | 2020-05-16 19:52:33 +0700 |
| commit | 56c992b6d3597e37e5dbfd7bbd63b7f1311c8b8e (patch) | |
| tree | 1fb660ab438c39d5ea9c99b2beb60126df3a77b7 /lib | |
| parent | 04a7f25930191e76928f575d796d2972811a4fac (diff) | |
| download | pakakeh.go-56c992b6d3597e37e5dbfd7bbd63b7f1311c8b8e.tar.xz | |
all: fix and suppress linter warnings
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/email/dkim/dns.go | 2 | ||||
| -rw-r--r-- | lib/email/dkim/key.go | 4 | ||||
| -rw-r--r-- | lib/email/dkim/signature.go | 6 | ||||
| -rw-r--r-- | lib/email/header.go | 2 | ||||
| -rw-r--r-- | lib/email/mime.go | 5 | ||||
| -rw-r--r-- | lib/floats64/floats64.go | 2 | ||||
| -rw-r--r-- | lib/http/client.go | 12 | ||||
| -rw-r--r-- | lib/http/responsetype.go | 2 | ||||
| -rw-r--r-- | lib/http/serveroptions.go | 18 | ||||
| -rw-r--r-- | lib/hunspell/hunspell.go | 2 | ||||
| -rw-r--r-- | lib/ini/ini.go | 32 | ||||
| -rw-r--r-- | lib/ints/ints.go | 2 | ||||
| -rw-r--r-- | lib/ints64/ints64.go | 2 | ||||
| -rw-r--r-- | lib/json/json_test.go | 2 | ||||
| -rw-r--r-- | lib/memfs/generate.go | 8 | ||||
| -rw-r--r-- | lib/memfs/generate_test/memfs_generate_test.go | 9 | ||||
| -rw-r--r-- | lib/memfs/memfs.go | 8 | ||||
| -rw-r--r-- | lib/memfs/node.go | 4 | ||||
| -rw-r--r-- | lib/mining/classifier/cart/cart.go | 2 | ||||
| -rw-r--r-- | lib/net/html/example_node_iterator_test.go | 2 | ||||
| -rw-r--r-- | lib/sql/client.go | 4 |
21 files changed, 61 insertions, 69 deletions
diff --git a/lib/email/dkim/dns.go b/lib/email/dkim/dns.go index e19f2501..1aa86089 100644 --- a/lib/email/dkim/dns.go +++ b/lib/email/dkim/dns.go @@ -60,7 +60,7 @@ func lookupDNSTXT(dname string) (key *Key, err error) { dns.QueryClassIN, []byte(dname)) if err != nil { dnsClientPool.Put(dnsClient) - return nil, fmt.Errorf("dkim: LookupKey: " + err.Error()) + return nil, fmt.Errorf("dkim: LookupKey: %w", err) } if dnsMsg.Header.RCode != dns.RCodeOK { dnsClientPool.Put(dnsClient) diff --git a/lib/email/dkim/key.go b/lib/email/dkim/key.go index b7baae4a..2b1912ed 100644 --- a/lib/email/dkim/key.go +++ b/lib/email/dkim/key.go @@ -185,12 +185,12 @@ func (key *Key) set(t *tag) (err error) { case tagDNSPublicKey: pkey, err := base64.RawStdEncoding.DecodeString(string(t.value)) if err != nil { - err = fmt.Errorf("dkim: error decode public key: " + err.Error()) + err = fmt.Errorf("dkim: error decode public key: %w", err) return err } pk, err := x509.ParsePKIXPublicKey(pkey) if err != nil { - err = fmt.Errorf("dkim: error parsing public key: " + err.Error()) + err = fmt.Errorf("dkim: error parsing public key: %w", err) return err } diff --git a/lib/email/dkim/signature.go b/lib/email/dkim/signature.go index d3dce197..9378ac0d 100644 --- a/lib/email/dkim/signature.go +++ b/lib/email/dkim/signature.go @@ -294,7 +294,7 @@ func (sig *Signature) Sign(pk *rsa.PrivateKey, hashHeader []byte) (err error) { rng := rand.Reader b, err := rsa.SignPKCS1v15(rng, pk, cryptoHash, hashHeader) if err != nil { - err = fmt.Errorf("email/dkim: failed to sign message: %s", err.Error()) + err = fmt.Errorf("email/dkim: failed to sign message: %w", err) return err } @@ -391,7 +391,7 @@ func (sig *Signature) Verify(key *Key, headerHash []byte) (err error) { sigValue := make([]byte, base64.StdEncoding.DecodedLen(len(sig.Value))) n, err := base64.StdEncoding.Decode(sigValue, sig.Value) if err != nil { - return fmt.Errorf("email/dkim: failed to decode signature: %s", err.Error()) + return fmt.Errorf("email/dkim: failed to decode signature: %w", err) } sigValue = sigValue[:n] @@ -402,7 +402,7 @@ func (sig *Signature) Verify(key *Key, headerHash []byte) (err error) { err = rsa.VerifyPKCS1v15(key.RSA, cryptoHash, headerHash, sigValue) if err != nil { - err = fmt.Errorf("email/dkim: verification failed: %s", err.Error()) + err = fmt.Errorf("email/dkim: verification failed: %w", err) } return err diff --git a/lib/email/header.go b/lib/email/header.go index 54e7ac36..236137e9 100644 --- a/lib/email/header.go +++ b/lib/email/header.go @@ -237,7 +237,7 @@ func (hdr *Header) SetMultipart() (err error) { return fmt.Errorf("email.SetMultipart: %w", err) } - hdr.Set(FieldTypeContentType, []byte(contentTypeMultipartAlternative)) + err = hdr.Set(FieldTypeContentType, []byte(contentTypeMultipartAlternative)) if err != nil { return fmt.Errorf("email.SetMultipart: %w", err) } diff --git a/lib/email/mime.go b/lib/email/mime.go index 811a2e56..edc62202 100644 --- a/lib/email/mime.go +++ b/lib/email/mime.go @@ -49,7 +49,10 @@ func newMIME(contentType, content []byte) (mime *MIME, err error) { var buf bytes.Buffer content = append(content, []byte("\r\n")...) w := quotedprintable.NewWriter(&buf) - w.Write(content) + _, err = w.Write(content) + if err != nil { + return nil, err + } w.Close() mime.Content = buf.Bytes() diff --git a/lib/floats64/floats64.go b/lib/floats64/floats64.go index 008e1338..1a75186d 100644 --- a/lib/floats64/floats64.go +++ b/lib/floats64/floats64.go @@ -330,7 +330,7 @@ func inplaceMerge(d []float64, idx []int, x, y, r int, asc bool) { } } -// (4.3.4) LET Y := the minimum value between x and r on `d` +// (4.3.4) LET Y := the minimum value between x and r on `d`. func minY(d []float64, x, y *int, r int, asc bool) { for *x < r { if asc { diff --git a/lib/http/client.go b/lib/http/client.go index 67342fd9..661e57a8 100644 --- a/lib/http/client.go +++ b/lib/http/client.go @@ -75,7 +75,7 @@ func NewClient(serverURL string, headers http.Header, insecure bool) (client *Cl MaxIdleConns: 100, IdleConnTimeout: 90 * time.Second, TLSClientConfig: &tls.Config{ - InsecureSkipVerify: insecure, + InsecureSkipVerify: insecure, //nolint: gosec }, TLSHandshakeTimeout: 10 * time.Second, ExpectContinueTimeout: 1 * time.Second, @@ -138,7 +138,7 @@ func (client *Client) PostForm(path string, params url.Values) ( httpReq, err := http.NewRequest(http.MethodPost, url, body) if err != nil { - return nil, fmt.Errorf("Post: %w", err) + return nil, fmt.Errorf("client.PostForm: %w", err) } client.setHeaders(httpReq) @@ -146,17 +146,17 @@ func (client *Client) PostForm(path string, params url.Values) ( httpRes, err := client.Client.Do(httpReq) if err != nil { - return nil, fmt.Errorf("Post: %w", err) + return nil, fmt.Errorf("client.PostForm: %w", err) } resBody, err = ioutil.ReadAll(httpRes.Body) if err != nil { - return nil, fmt.Errorf("Post: %w", err) + return nil, fmt.Errorf("client.PostForm: %w", err) } err = httpRes.Body.Close() if err != nil { - return nil, fmt.Errorf("Post: %w", err) + return nil, fmt.Errorf("client.PostForm: %w", err) } return client.uncompress(httpRes, resBody) @@ -180,7 +180,7 @@ func (client *Client) PostFormData(path string, params map[string][]byte) ( httpReq, err := http.NewRequest(http.MethodPost, url, body) if err != nil { - return nil, fmt.Errorf("Post: %w", err) + return nil, fmt.Errorf("http: PostFormData: %w", err) } client.setHeaders(httpReq) diff --git a/lib/http/responsetype.go b/lib/http/responsetype.go index 3cb4254d..ecd11d6f 100644 --- a/lib/http/responsetype.go +++ b/lib/http/responsetype.go @@ -4,7 +4,7 @@ package http -// ResponseType define type for HTTP response +// ResponseType define type for HTTP response. type ResponseType int // List of valid response type. diff --git a/lib/http/serveroptions.go b/lib/http/serveroptions.go index 71278857..13cd6ac5 100644 --- a/lib/http/serveroptions.go +++ b/lib/http/serveroptions.go @@ -37,28 +37,23 @@ type ServerOptions struct { // This field is optional. Excludes []string - // CORSAllowCredentials indicates whether or not the actual request - // can be made using credentials. - CORSAllowCredentials bool - // CORSAllowOrigins contains global list of cross-site Origin that are // allowed during preflight requests by the OPTIONS method. // The list is case-sensitive. // To allow all Origin, one must add "*" string to the list. - CORSAllowOrigins []string - corsAllowOriginsAll bool // flag to indicate wildcards on list. + CORSAllowOrigins []string // CORSAllowHeaders contains global list of allowed headers during // preflight requests by the OPTIONS method. // The list is case-insensitive. // To allow all headers, one must add "*" string to the list. - CORSAllowHeaders []string - corsAllowHeadersAll bool // flag to indicate wildcards on list. + CORSAllowHeaders []string // CORSExposeHeaders contains list of allowed headers. // This list will be send when browser request OPTIONS without // request-method. CORSExposeHeaders []string + exposeHeaders string // CORSMaxAge gives the value in seconds for how long the response to // the preflight request can be cached for without sending another @@ -66,11 +61,16 @@ type ServerOptions struct { CORSMaxAge int corsMaxAge string + // CORSAllowCredentials indicates whether or not the actual request + // can be made using credentials. + CORSAllowCredentials bool + // Development if its true, the Root file system is served by reading // the content directly instead of using memory file system. Development bool - exposeHeaders string + corsAllowHeadersAll bool // flag to indicate wildcards on list. + corsAllowOriginsAll bool // flag to indicate wildcards on list. } func (opts *ServerOptions) init() { diff --git a/lib/hunspell/hunspell.go b/lib/hunspell/hunspell.go index ba87b543..b961b574 100644 --- a/lib/hunspell/hunspell.go +++ b/lib/hunspell/hunspell.go @@ -81,7 +81,7 @@ const ( optSFX = "SFX" ) -// List of affix file other options/ +// List of affix file other options. const ( optCircumfix = "CIRCUMFIX" optForbiddenWord = "FORBIDDENWORD" diff --git a/lib/ini/ini.go b/lib/ini/ini.go index ea0bc637..38138272 100644 --- a/lib/ini/ini.go +++ b/lib/ini/ini.go @@ -91,12 +91,12 @@ func Marshal(v interface{}) (b []byte, err error) { return nil, fmt.Errorf("marshal: expecting struct, got %v", kind) } - ini := &Ini{} + in := &Ini{} - marshalStruct(ini, rtipe, rvalue) + marshalStruct(in, rtipe, rvalue) buf := bytes.NewBuffer(nil) - err = ini.Write(buf) + err = in.Write(buf) if err != nil { return nil, err } @@ -239,7 +239,7 @@ func (in *Ini) Unmarshal(v interface{}) (err error) { } //nolint: gocyclo -func (ini *Ini) unmarshalToStruct(rtipe reflect.Type, rvalue reflect.Value) { +func (in *Ini) unmarshalToStruct(rtipe reflect.Type, rvalue reflect.Value) { numField := rtipe.NumField() if numField == 0 { return @@ -255,7 +255,7 @@ func (ini *Ini) unmarshalToStruct(rtipe reflect.Type, rvalue reflect.Value) { continue } - tag := field.Tag.Get("ini") + tag := field.Tag.Get(fieldTagName) if len(tag) == 0 && kind != reflect.Struct { continue } @@ -290,18 +290,18 @@ func (ini *Ini) unmarshalToStruct(rtipe reflect.Type, rvalue reflect.Value) { switch kind { case reflect.Bool: - valString, _ := ini.Get(sec, sub, key, "") + valString, _ := in.Get(sec, sub, key, "") if IsValueBoolTrue(valString) { fvalue.SetBool(true) } case reflect.String: - valString, _ := ini.Get(sec, sub, key, "") + valString, _ := in.Get(sec, sub, key, "") fvalue.SetString(valString) case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - valString, _ := ini.Get(sec, sub, key, "") + valString, _ := in.Get(sec, sub, key, "") _, ok := fvalue.Interface().(time.Duration) if ok { @@ -321,7 +321,7 @@ func (ini *Ini) unmarshalToStruct(rtipe reflect.Type, rvalue reflect.Value) { case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: - valString, _ := ini.Get(sec, sub, key, "") + valString, _ := in.Get(sec, sub, key, "") u64, err := strconv.ParseUint(valString, 10, 64) if err != nil { @@ -330,7 +330,7 @@ func (ini *Ini) unmarshalToStruct(rtipe reflect.Type, rvalue reflect.Value) { fvalue.SetUint(u64) case reflect.Float32, reflect.Float64: - valString, _ := ini.Get(sec, sub, key, "") + valString, _ := in.Get(sec, sub, key, "") f64, err := strconv.ParseFloat(valString, 64) if err != nil { @@ -339,11 +339,11 @@ func (ini *Ini) unmarshalToStruct(rtipe reflect.Type, rvalue reflect.Value) { fvalue.SetFloat(f64) case reflect.Array: - vals := ini.Gets(sec, sub, key) + vals := in.Gets(sec, sub, key) fvalue.Set(unmarshalSlice(ftype.Elem(), fvalue, vals)) case reflect.Slice: - vals := ini.Gets(sec, sub, key) + vals := in.Gets(sec, sub, key) fvalue.Set(unmarshalSlice(ftype.Elem(), fvalue, vals)) case reflect.Map: @@ -351,7 +351,7 @@ func (ini *Ini) unmarshalToStruct(rtipe reflect.Type, rvalue reflect.Value) { continue } - vals := ini.AsMap(sec, sub) + vals := in.AsMap(sec, sub) amap := reflect.MakeMap(ftype) fvalue.Set(unmarshalMap(ftype.Elem(), amap, vals)) @@ -361,7 +361,7 @@ func (ini *Ini) unmarshalToStruct(rtipe reflect.Type, rvalue reflect.Value) { kind = ftype.Kind() } - valString, _ := ini.Get(sec, sub, key, "") + valString, _ := in.Get(sec, sub, key, "") ptrval := reflect.New(ftype) unmarshalPtr(ftype, ptrval.Elem(), valString) @@ -372,7 +372,7 @@ func (ini *Ini) unmarshalToStruct(rtipe reflect.Type, rvalue reflect.Value) { _, ok := vi.(time.Time) if ok { - valString, _ := ini.Get(sec, sub, key, "") + valString, _ := in.Get(sec, sub, key, "") t, err := time.Parse(layout, valString) if err != nil { @@ -383,7 +383,7 @@ func (ini *Ini) unmarshalToStruct(rtipe reflect.Type, rvalue reflect.Value) { continue } - ini.unmarshalToStruct(reflect.TypeOf(vi), fvalue.Addr().Elem()) + in.unmarshalToStruct(reflect.TypeOf(vi), fvalue.Addr().Elem()) case reflect.Invalid, reflect.Chan, reflect.Func, reflect.UnsafePointer, reflect.Interface: diff --git a/lib/ints/ints.go b/lib/ints/ints.go index 188342d7..aea2414a 100644 --- a/lib/ints/ints.go +++ b/lib/ints/ints.go @@ -393,7 +393,7 @@ func inplaceMultiswap(d []int, idx []int, x, y, ylast int) int { return y } -// (4.3.4) LET Y := the minimum value between x and r on `d` +// (4.3.4) LET Y := the minimum value between x and r on `d`. func minY(d []int, x, y *int, r int, asc bool) { for *x < r { if asc { diff --git a/lib/ints64/ints64.go b/lib/ints64/ints64.go index 1ae8c484..9d05a30a 100644 --- a/lib/ints64/ints64.go +++ b/lib/ints64/ints64.go @@ -326,7 +326,7 @@ func inplaceMerge(d []int64, idx []int, x, y, r int, asc bool) { } } -// (4.3.4) LET Y := the minimum value between x and r on `d` +// (4.3.4) LET Y := the minimum value between x and r on `d`. func minY(d []int64, x, y *int, r int, asc bool) { for *x < r { if asc { diff --git a/lib/json/json_test.go b/lib/json/json_test.go index 1efa9708..d1779f22 100644 --- a/lib/json/json_test.go +++ b/lib/json/json_test.go @@ -89,7 +89,7 @@ func TestUnescapeString(t *testing.T) { exp: ` this\ is //\"☺"`, }, { - in: `\u0002\b\f\u000E\u000F\u0010\u0014\u001E\u001F\u263A `, //nolint: stylecheck + in: `\u0002\b\f\u000E\u000F\u0010\u0014\u001E\u001F\u263A `, exp: `☺ `}, { //nolint: stylecheck in: `\uerror`, expErr: `strconv.ParseUint: parsing "erro": invalid syntax`, diff --git a/lib/memfs/generate.go b/lib/memfs/generate.go index 3a9455ac..72bacba7 100644 --- a/lib/memfs/generate.go +++ b/lib/memfs/generate.go @@ -37,13 +37,13 @@ func (mfs *MemFS) GoGenerate(pkgName, out, contentEncoding string) (err error) { f, err := os.Create(out) if err != nil { - return fmt.Errorf("memfs: GoGenerate: " + err.Error()) + return fmt.Errorf("memfs: GoGenerate: %w", err) } if len(contentEncoding) > 0 { err = mfs.ContentEncode(contentEncoding) if err != nil { - return fmt.Errorf("GoGenerate: " + err.Error()) + return fmt.Errorf("GoGenerate: %w", err) } } @@ -81,11 +81,11 @@ func (mfs *MemFS) GoGenerate(pkgName, out, contentEncoding string) (err error) { err = f.Close() if err != nil { - return fmt.Errorf("memfs: GoGenerate: " + err.Error()) + return fmt.Errorf("memfs: GoGenerate: %w", err) } return nil fail: _ = f.Close() - return fmt.Errorf("memfs: GoGenerate: " + err.Error()) + return fmt.Errorf("memfs: GoGenerate: %w", err) } diff --git a/lib/memfs/generate_test/memfs_generate_test.go b/lib/memfs/generate_test/memfs_generate_test.go index e27ce17c..3d1b886a 100644 --- a/lib/memfs/generate_test/memfs_generate_test.go +++ b/lib/memfs/generate_test/memfs_generate_test.go @@ -5,10 +5,8 @@ package test import ( - "os" "path/filepath" "sort" - "strings" "testing" "github.com/shuLhan/share/lib/memfs" @@ -16,13 +14,6 @@ import ( ) func TestGeneratePathNode(t *testing.T) { - wd, err := os.Getwd() - if err != nil { - t.Fatal(err) - } - - wd = strings.TrimSuffix(wd, "generate_test") - expRoot := &memfs.Node{ SysPath: "testdata", Path: "/", diff --git a/lib/memfs/memfs.go b/lib/memfs/memfs.go index 0ea7caa4..ebfb72d0 100644 --- a/lib/memfs/memfs.go +++ b/lib/memfs/memfs.go @@ -143,12 +143,12 @@ func (mfs *MemFS) AddFile(path string) (*Node, error) { fi, err := os.Stat(path) if err != nil { - return nil, fmt.Errorf("memfs.AddFile: " + err.Error()) + return nil, fmt.Errorf("memfs.AddFile: %w", err) } node, err = NewNode(parent, fi, mfs.withContent) if err != nil { - return nil, fmt.Errorf("memfs.AddFile: " + err.Error()) + return nil, fmt.Errorf("memfs.AddFile: %w", err) } if parent == nil { @@ -196,12 +196,12 @@ func (mfs *MemFS) ContentEncode(encoding string) (err error) { _, err = encoder.Write(node.V) if err != nil { - return fmt.Errorf("memfs.ContentEncode: " + err.Error()) + return fmt.Errorf("memfs.ContentEncode: %w", err) } err = encoder.Close() if err != nil { - return fmt.Errorf("memfs.ContentEncode: " + err.Error()) + return fmt.Errorf("memfs.ContentEncode: %w", err) } node.V = make([]byte, buf.Len()) diff --git a/lib/memfs/node.go b/lib/memfs/node.go index 51e83525..8bbf0fe7 100644 --- a/lib/memfs/node.go +++ b/lib/memfs/node.go @@ -360,8 +360,8 @@ func (leaf *Node) update(newInfo os.FileInfo, withContent bool) (err error) { if newInfo == nil { newInfo, err = os.Stat(leaf.SysPath) if err != nil { - return fmt.Errorf("lib/memfs: Node.update %q: %s", - leaf.Path, err.Error()) + return fmt.Errorf("lib/memfs: Node.update %q: %w", + leaf.Path, err) } } diff --git a/lib/mining/classifier/cart/cart.go b/lib/mining/classifier/cart/cart.go index 1745bb8f..5cf20c8d 100644 --- a/lib/mining/classifier/cart/cart.go +++ b/lib/mining/classifier/cart/cart.go @@ -257,7 +257,7 @@ func (runtime *Runtime) splitTreeByGain(claset tabula.ClasetInterface) ( } // SelectRandomFeature if NRandomFeature is greater than zero, select and -// compute gain in n random features instead of in all features +// compute gain in n random features instead of in all features. func (runtime *Runtime) SelectRandomFeature(claset tabula.ClasetInterface) { if runtime.NRandomFeature <= 0 { // all features selected diff --git a/lib/net/html/example_node_iterator_test.go b/lib/net/html/example_node_iterator_test.go index b5e82db4..6fa3838f 100644 --- a/lib/net/html/example_node_iterator_test.go +++ b/lib/net/html/example_node_iterator_test.go @@ -52,7 +52,7 @@ func ExampleParse() { //html } -func ExampleNodeIterator_Set() { +func ExampleNodeIterator_SetNext() { rawHTML := ` <ul> <li> diff --git a/lib/sql/client.go b/lib/sql/client.go index 82bb8c20..81f85961 100644 --- a/lib/sql/client.go +++ b/lib/sql/client.go @@ -19,9 +19,7 @@ import ( ) const ( - sqlExtension = ".sql" - sqlComment = "--" - sqlTerminator = ';' + sqlExtension = ".sql" ) // |
