urlshort
urlshort copied to clipboard
YAMLHandler does not work as expected
I was following instructions in the video, wrote code exactly as Jon, but redirecting for "/urlshort" and "/urlshort-final" don't work. yaml.Unmarshal(yml, &pathUrls) returns only [{/urlshort }] for some reason. Does it have something to do with tags added to struct? In the video he added yaml tags automatically. I use VS Code and when I tried it struct became this:
type pathUrl struct {
Path string `json:"path,omitempty"`
URL string `json:"url,omitempty"`
}
I changed it to yaml:"path" and yaml:"url", still does not work.
To get the package, execute:
go get gopkg.in/yaml.v2 To import this package, add the following line to your code:
import "gopkg.in/yaml.v2" Refer to it as yaml.