mirror of
https://github.com/unti-io/go-utils.git
synced 2025-10-06 08:46:54 +08:00
[v1.4.2] ToStringMap
This commit is contained in:
@@ -180,6 +180,12 @@ func (this *AsciiStruct) ToString(params map[string]any) (result string) {
|
||||
}
|
||||
}
|
||||
|
||||
// 返回排序后的字符串
|
||||
return item.String()
|
||||
// 去除最后一个 &
|
||||
text := item.String()
|
||||
if len(text) > 0 {
|
||||
text = text[:len(text)-1]
|
||||
}
|
||||
|
||||
// 返回排序后的字符串
|
||||
return text
|
||||
}
|
@@ -328,8 +328,8 @@ func (this *RSAStruct) Decrypt(privateKey, text string) (result *RSAResponse) {
|
||||
return result
|
||||
}
|
||||
|
||||
// PemPublicKey - 输出完整的 PEM 格式公钥证书
|
||||
func (this *RSAStruct) PemPublicKey(key string) (string, error) {
|
||||
// PublicPem - 输出完整的 PEM 格式公钥证书
|
||||
func (this *RSAStruct) PublicPem(key string) (cert string) {
|
||||
|
||||
// 创建 PEM 格式块
|
||||
block := &pem.Block{
|
||||
@@ -338,16 +338,14 @@ func (this *RSAStruct) PemPublicKey(key string) (string, error) {
|
||||
}
|
||||
|
||||
// 生成完整的 PEM 证书字符串
|
||||
var pemBuf bytes.Buffer
|
||||
if err := pem.Encode(&pemBuf, block); err != nil {
|
||||
return "", err
|
||||
var PEM bytes.Buffer
|
||||
if err := pem.Encode(&PEM, block); err != nil { return "" }
|
||||
|
||||
return PEM.String()
|
||||
}
|
||||
|
||||
return pemBuf.String(), nil
|
||||
}
|
||||
|
||||
// PemPrivateKey - 输出完整的 PEM 格式私钥证书
|
||||
func (this *RSAStruct) PemPrivateKey(key string) (string, error) {
|
||||
// PrivatePem - 输出完整的 PEM 格式私钥证书
|
||||
func (this *RSAStruct) PrivatePem(key string) (cert string) {
|
||||
|
||||
// 创建 PEM 格式块
|
||||
block := &pem.Block{
|
||||
@@ -356,10 +354,8 @@ func (this *RSAStruct) PemPrivateKey(key string) (string, error) {
|
||||
}
|
||||
|
||||
// 生成完整的 PEM 证书字符串
|
||||
var pemBuf bytes.Buffer
|
||||
if err := pem.Encode(&pemBuf, block); err != nil {
|
||||
return "", err
|
||||
}
|
||||
var PEM bytes.Buffer
|
||||
if err := pem.Encode(&PEM, block); err != nil { return "" }
|
||||
|
||||
return pemBuf.String(), nil
|
||||
return PEM.String()
|
||||
}
|
@@ -177,3 +177,8 @@ func (this *StructStruct) Slice(obj any) (slice []any) {
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// ToStringMap - 将结构体转换为map[string]any
|
||||
func (this *StructStruct) ToStringMap(obj any) (result map[string]any) {
|
||||
return cast.ToStringMap(Json.Encode(obj))
|
||||
}
|
Reference in New Issue
Block a user