我需要根据上级(Type
字段)中字段值中的变量实现自定义解组逻辑(VerifyingKey
字段).我可以将情况分解如下(源自Unmarshal remaining JSON after performing custom unmarshalling)
type SingleKey struct {
Type string `json:"type"`
Others OtherFields `json:"wrapped_fields"`
}
type OtherFields struct {
FQDN string `json:"fqdn"`
Address string `json:"address"`
Nonce int64 `json:"nonce"`
Challenge []byte `json:"challenge"`
NetworkID string `json:"network_id"`
VerifyingKey []PublicKey `json:"verifying_key"`
Signature []byte `json:"signature"`
}
// Interface for Public Key
type PublicKey interface {
// Methods specific to public key functionality
}
// Example concrete implementations (replace with your actual types)
type RsaPublicKey struct {
PublicKey
// ... (fields specific to RSA public key)
}
type EcdsaPublicKey struct {
PublicKey
// ... (fields specific to ECDSA public key)
}
我try 过很多替代方案,但我无法找到解决方案.