Let's say I have a struct which should be used as a result for an upload:
type uploadResult struct {
Filename string `json:"filename"`
Code string `json:"code"`
Reason string `json:"reason"`
}
There will be other structs like this one, both having a field Code
and another one called Reason
. It would therefore be interesting to have something like a common interface (pseudo-go-code; this one doesn't work):
type apiResult interface {
Code string `json:"code"`
Reason string `json:"reason"`
}
Because I would like to call a function which extracts some common fields, but only those that are common:
func failExit(result apiResult) {
fmt.Println(result.Reason)
}
So how would I rewrite it so that it does what I'm expecting?
Best regards