probo/models/response.go

30 lines
517 B
Go
Raw Normal View History

2023-12-11 09:32:50 +01:00
package models
import (
"crypto/sha256"
"encoding/json"
"fmt"
)
type Response struct {
Meta
QuestionID string
AnswerID string
}
func (r *Response) String() string {
return fmt.Sprintf("QID: %v, AID:%v", r.QuestionID, r.AnswerID)
}
func (r *Response) GetHash() string {
return fmt.Sprintf("%x", sha256.Sum256([]byte(r.QuestionID+r.AnswerID)))
}
func (r *Response) Marshal() ([]byte, error) {
return json.Marshal(r)
}
func (r *Response) Unmarshal(data []byte) error {
return json.Unmarshal(data, r)
}