尝试优化代码

This commit is contained in:
wyx2685
2024-01-25 23:06:37 +09:00
parent e292b3b0e7
commit 91e78fbc20
7 changed files with 66 additions and 24 deletions

View File

@@ -262,12 +262,14 @@ func (u *User) DecodePrivate(pemEncodedPriv string) (*ecdsa.PrivateKey, error) {
privateKey, err := x509.ParseECPrivateKey(x509EncodedPriv)
return privateKey, err
}
func (u *User) Load(path string) error {
f, err := os.Open(path)
data, err := os.ReadFile(path)
if err != nil {
return fmt.Errorf("open file error: %s", err)
}
err = json.NewDecoder(f).Decode(u)
err = json.Unmarshal(data, u)
if err != nil {
return fmt.Errorf("unmarshal json error: %s", err)
}