I have an interface like,
type cacheControlDirectives interface {
setDirective(key string, value string) error
}
And two structs implement it like,
type requestCacheControlDirectives struct {
//...
}
func (rqcd *requestCacheControlDirectives) setDirective(key string, value string) error {
//...
}
type responseCacheControlDirectives struct {
//...
}
func (rqcd *responseCacheControlDirectives) setDirective(key string, value string) error {
//...
}
I have a function to parse the input string and assign the values to the respective structs.
func parseCacheControl(value string, ccd cacheControlDirectives) (cacheControlDirectives, []error) {
var err []error
directives := strings.Split(value, ",")
for _, directive := range directives {
directive := strings.TrimSpace(directive)
s := strings.Split(directive, "=")
if len(s) == 1 {
e := ccd.setDirective(s[0], "true")
if e != nil {
err = append(err, e)
}
} else if len(s) == 2 {
ccd.setDirective(s[0], s[1])
}
}
return ccd, err
}
Now when I try to use this function like this,
rqcd, e := parseCacheControl(req.Header.Get("Cache-Control"), &requestCacheControlDirectives{})
if e != nil {
err = append(err, e...)
}
var rd requestCacheControlDirectives
rd = rqcd
It’s showing cannot use rqcd (type cacheControlDirectives) as type requestCacheControlDirectives in assignment
error. How to solve this?