Skip to content

Commit

Permalink
fix: .golangci.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
gorpher committed Apr 1, 2023
1 parent 2d5cfe0 commit 454eb8a
Show file tree
Hide file tree
Showing 14 changed files with 156 additions and 818 deletions.
696 changes: 95 additions & 601 deletions .golangci.yml

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ func (a *Audience) UnmarshalJSON(b []byte) error {
case []interface{}:
aud := make(Audience, len(vv))
for i := range vv {
aud[i] = vv[i].(string)
if val, ok := vv[i].(string); ok {
aud[i] = val
}
}
*a = aud
}
Expand Down
16 changes: 0 additions & 16 deletions codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,3 @@ func TestJwtCodec(t *testing.T) {
}
t.Log(string(decode))
}

func equalMap(a, b map[string]interface{}) bool {
if len(a) != len(b) {
return false
}
for k, v1 := range a {
v2, ok := b[k]
if !ok {
return false
}
if !reflect.DeepEqual(v1, v2) {
return false
}
}
return true
}
5 changes: 3 additions & 2 deletions crypto_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const (

func BlockEncrypt(block cipher.Block, mode BlockStreamMode, value []byte) ([]byte, error) {
size := block.BlockSize()
iv := make([]byte, size)
iv := make([]byte, size, len(value))
_, err := io.ReadFull(rand.Reader, iv)
if err != nil {
return nil, err
Expand All @@ -116,7 +116,8 @@ func BlockEncrypt(block cipher.Block, mode BlockStreamMode, value []byte) ([]byt
encrypted := make([]byte, len(value))
stream.XORKeyStream(encrypted, value)
// 返回偏移量和密文
return append(iv, encrypted...), nil
iv = append(iv, encrypted...)
return iv, nil
}

func BlockDecrypt(block cipher.Block, mode BlockStreamMode, value []byte) ([]byte, error) {
Expand Down
10 changes: 5 additions & 5 deletions crypto_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (

"github.com/tjfoc/gmsm/pkcs12"
"github.com/tjfoc/gmsm/sm4"
"golang.org/x/crypto/blowfish"
"golang.org/x/crypto/cast5"
"golang.org/x/crypto/tea"
"golang.org/x/crypto/twofish"
"golang.org/x/crypto/xtea"
"golang.org/x/crypto/blowfish" // nolint
"golang.org/x/crypto/cast5" // nolint
"golang.org/x/crypto/tea" // nolint
"golang.org/x/crypto/twofish" // nolint
"golang.org/x/crypto/xtea" // nolint
)

func TestAesEncryptCBC(t *testing.T) {
Expand Down
7 changes: 2 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ go 1.18
require (
github.com/bwmarrin/snowflake v0.3.0
github.com/google/go-cmp v0.4.1
github.com/google/uuid v1.3.0
github.com/rs/xid v1.4.0
github.com/satori/go.uuid v1.2.0
github.com/shopspring/decimal v1.3.1
github.com/tjfoc/gmsm v1.4.1
golang.org/x/crypto v0.4.0
)

require (
golang.org/x/sys v0.3.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
)
require golang.org/x/sys v0.3.0 // indirect
94 changes: 0 additions & 94 deletions go.sum

This file was deleted.

57 changes: 8 additions & 49 deletions http_file.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package gone

import (
"bytes"
"crypto/md5"
"crypto/sha1"
"crypto/sha256"
Expand Down Expand Up @@ -45,7 +44,7 @@ func (h *HTTPReceiveFile) String() string {
"FileMIME": h.FileMIME,
"TotalSize": h.TotalSize,
}
body, _ := json.Marshal(m)
body, _ := json.Marshal(m) // nolint
return string(body)
}

Expand Down Expand Up @@ -115,7 +114,7 @@ func WithReceiveFileDstDir(dstDir string) ReceiveFileOption {
func NewHttpReceiveFile(options ...ReceiveFileOption) func(r *http.Request) (HTTPReceiveFile, error) {
return func(r *http.Request) (HTTPReceiveFile, error) {
h := HTTPReceiveFile{
MaxReceiveSize: GB, //默认最大1G
MaxReceiveSize: GB,
FieldName: "file",
DstDirMode: os.ModePerm,
DstFileMode: os.FileMode(0755),
Expand All @@ -133,7 +132,7 @@ func NewHttpReceiveFile(options ...ReceiveFileOption) func(r *http.Request) (HTT
if err != nil {
return h, err
}
defer srcFile.Close()
defer srcFile.Close() //nolint
h.fileHeader = info
h.DstFilename = info.Filename
for _, opt := range options {
Expand Down Expand Up @@ -164,7 +163,10 @@ func NewHttpReceiveFile(options ...ReceiveFileOption) func(r *http.Request) (HTT
if err != nil {
return h, err
}
tempFile.Close()
err = tempFile.Close()
if err != nil {
return h, err
}
h.Checksum = hex.EncodeToString(h.Hash.Sum(nil))
h.Hash.Reset()
err = os.Rename(tempFile.Name(), filepath.Join(h.DstDir, h.DstFilename))
Expand All @@ -177,7 +179,7 @@ func NewHttpReceiveFile(options ...ReceiveFileOption) func(r *http.Request) (HTT
}

func getSize(content io.Seeker) (int64, error) {
size, err := content.Seek(0, os.SEEK_END)
size, err := content.Seek(0, io.SeekEnd)
if err != nil {
return 0, err
}
Expand All @@ -187,46 +189,3 @@ func getSize(content io.Seeker) (int64, error) {
}
return size, nil
}

// HttpSendFile send http file
func HttpSendFile(url, filePath string) error {
method := "POST"
payload := &bytes.Buffer{}
writer := multipart.NewWriter(payload)
file, err := os.Open(filePath)
if err != nil {
return err
}
defer file.Close()
var partFile io.Writer
partFile, err = writer.CreateFormFile("file", filepath.Base(filePath))
if err != nil {
return err
}
_, err = io.Copy(partFile, file)
if err != nil {
return err
}
err = writer.Close()
if err != nil {
return err
}
client := &http.Client{}
var (
req *http.Request
res *http.Response
)
req, err = http.NewRequest(method, url, payload)
if err != nil {
return err
}
req.Header.Set("Content-Type", writer.FormDataContentType())
res, err = client.Do(req)
if err != nil {
return err
}
if !(res.StatusCode == 200 || res.StatusCode == 204) {
return fmt.Errorf("invalid status code %d", res.StatusCode)
}
return err
}
6 changes: 3 additions & 3 deletions id.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"
"time"

uuid "github.com/satori/go.uuid"
uuid "github.com/google/uuid"

"github.com/bwmarrin/snowflake"
"github.com/rs/xid"
Expand Down Expand Up @@ -43,7 +43,7 @@ func (i *id) XID() xid.ID {
}

func (i *id) UUID4() uuid.UUID {
return uuid.NewV4()
return uuid.New()
}

func (i *id) SInt64() int64 {
Expand All @@ -59,7 +59,7 @@ func (i *id) XString() string {
}

func (i *id) UString() string {
return uuid.NewV4().String()
return uuid.New().String()
}

// RandString 最大64个字母.
Expand Down
9 changes: 0 additions & 9 deletions jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,6 @@ func VerifyJwtSignByRsa(ciphertext []byte, publicKey *rsa.PublicKey) (json.RawMe
return nil, err
}
var header Header
if err != nil {
return nil, err
}
err = json.Unmarshal(hb, &header)
if err != nil {
return nil, err
Expand Down Expand Up @@ -225,9 +222,6 @@ func VerifyJwtSignByEcdsa(ciphertext []byte, publicKey *ecdsa.PublicKey) (json.R
return nil, err
}
var header Header
if err != nil {
return nil, err
}
err = json.Unmarshal(hb, &header)
if err != nil {
return nil, err
Expand Down Expand Up @@ -281,9 +275,6 @@ func VerifyJwtSignByHmacHash(ciphertext, key []byte) (json.RawMessage, error) {
}

var header Header
if err != nil {
return nil, err
}
err = json.Unmarshal(hb, &header)
if err != nil {
return nil, err
Expand Down
Loading

0 comments on commit 454eb8a

Please sign in to comment.