Git Commit History: Github

When I started this challenge I had already spent a bit of time getting to know the net/http package, so I didn’t find it especially difficult, but I enjoyed the chance to practice with opening and reading files, specifically YAML and JSON files.

Unmarshaling JSON && YAML

Not having taken computer science in school I had no idea what marshaling was; I first saw the terms marshal and unmarshal when starting with Go.

Read more about marshaling here.

Here’s how you transform or unmarshal yaml to a Go struct:

1
2
3
4
5
6
7
8
9
// Just inline the struct.
// No need for a named type
// before we need this struct elsewhere.
yamlMappings := []struct {
    Path string `yaml:"path"`
    URL  string `yaml:"url"`
}{}

err := yaml.Unmarshal(yml, &yamlMappings)

For this challenge I prefered to use an anonymous struct, but you could define it if you needed it elsewhere.

Keeping It Simple?

As noted in my commit message I prefered to focus my code on creating different parsers that appended new redirects a master redirect map - map[string]string rather than creating parsers AND buildling separate maps to be used in distinct handlers.

I suppose it’s a small, maybe unimportant, difference, but this approach suits my brain better.