-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
doodle
committed
May 24, 2022
0 parents
commit d7fca2e
Showing
6 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package cryptx | ||
|
||
import ( | ||
"fmt" | ||
"golang.org/x/crypto/scrypt" | ||
) | ||
|
||
func PasswordEncrypt (salt, password string) string { | ||
dk, _ := scrypt.Key([]byte(password), []byte(salt), 32768, 8, 1, 32) | ||
return fmt.Sprintf("%x", string(dk)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package cryptx | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestPasswordEncrypt(t *testing.T) { | ||
salt := "HWVOFkGgPTryzICwd7qnJaZR9KQ2i8xe" | ||
password := "123456" | ||
encrypt := PasswordEncrypt(salt, password) | ||
fmt.Println(encrypt) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package errorx | ||
|
||
const defaultCode = 1001 | ||
|
||
type CodeError struct { | ||
Code int `json:"code"` | ||
Msg string `json:"msg"` | ||
} | ||
|
||
type CodeErrorResponse struct { | ||
Code int `json:"code"` | ||
Msg string `json:"msg"` | ||
} | ||
|
||
func NewCodeError(code int, msg string) error { | ||
return &CodeError{Code: code, Msg: msg} | ||
} | ||
|
||
func NewDefaultError(msg string) error { | ||
return NewCodeError(defaultCode, msg) | ||
} | ||
|
||
func (e *CodeError) Error() string { | ||
return e.Msg | ||
} | ||
|
||
func (e *CodeError) Data() *CodeErrorResponse { | ||
return &CodeErrorResponse{ | ||
Code: e.Code, | ||
Msg: e.Msg, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package res | ||
|
||
type Body struct { | ||
Code int `json:"code"` | ||
Msg string `json:"msg"` | ||
Data interface{} `json:"data,omitempty"` | ||
} | ||
|
||
func Response (resp interface{}, err error) Body { | ||
var body Body | ||
if err != nil { | ||
body.Code = -1 | ||
body.Msg = err.Error() | ||
} else { | ||
body.Msg = "OK" | ||
body.Data = resp | ||
} | ||
return body | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module github.com/doodle971002/stools | ||
|
||
go 1.18 | ||
|
||
require golang.org/x/crypto v0.0.0-20220518034528-6f7dac969898 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
golang.org/x/crypto v0.0.0-20220518034528-6f7dac969898 h1:SLP7Q4Di66FONjDJbCYrCRrh97focO6sLogHO7/g8F0= | ||
golang.org/x/crypto v0.0.0-20220518034528-6f7dac969898/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= |