我正在尝试从消息和秘密生成 HMAC 256 哈希。但是当我返回它时,它是不正确的。
func makeSig(s Signature) string {
secretHash := md5.New()
secretHash.Write([]byte("secret"))
key := secretHash.Sum(nil)
fmt.Println("The secret key is ", hex.EncodeToString(key))
message := strings.Join([]string{"one", "two", "three"}, "")
fmt.Println("The message is ", message)
sig := hmac.New(sha256.New, key)
sig.Write([]byte(message))
return hex.EncodeToString(sig.Sum(nil))
}
Run Code Online (Sandbox Code Playgroud)
不知道有什么问题,请指教。
我有这个嵌套的 golang 结构:
// TierRequest is the outer most XML envelope of soap request
type TierRequest struct {
XMLName xml.Name `xml:"soapenv:Envelope"`
NsEnv string `xml:"xmlns:soapenv,attr"`
NsType string `xml:"xmlns:typ,attr"`
Header string `xml:"soapenv:Header"`
// TierBody is an emtpy container with the GetCollectorProfile struct
type TierBody struct {
GetCollectorProfiles GetCollectorProfile `Collectorxml:"typ:GetCollectorProfileRequest"`
}
// GetCollectorProfile struct has the context and collector number
type GetCollectorProfile struct {
Contexts CollectorContext `xml:"typ:Context"`
Number int `xml:"typ:CollectorNumber"`
}
// CollectorContext contanins a few variables as attributes
type CollectorContext struct { …Run Code Online (Sandbox Code Playgroud) 我一直在努力解析一个基本的数组响应。
我的输入 JSON 有一个结构类型一致的列表。
[
{
"amount":"6.40000000",
"date":"1439165701",
"price":"350.26",
"tid":104159
},
{
"amount":"0.10025000",
"date":"1439162764",
"price":"351.03",
"tid":104150
}
]
Run Code Online (Sandbox Code Playgroud)
我的结构有一个嵌套的数组结构。
type TransactionResponse struct {
Transaction []Transaction
}
type Transaction struct {
Amount string `json:"amount"`
Date string `json:"date"`
Price string `json:"price"`
tid uint `json:"tid"`
}
Run Code Online (Sandbox Code Playgroud)
解析json的函数:
func main() {
var transactions TransactionResponse
body, err := http.Get(url)
err = json.Unmarshal(body, &transactions)
}
Run Code Online (Sandbox Code Playgroud)
我哪里错了?