https://github.com/evgeniy-dammer/urlshortener
"URL Shortener" exercise from Gophercises (by John Calhoun)
https://github.com/evgeniy-dammer/urlshortener
go golang gophercises url-shortener urlshortener
Last synced: 9 months ago
JSON representation
"URL Shortener" exercise from Gophercises (by John Calhoun)
- Host: GitHub
- URL: https://github.com/evgeniy-dammer/urlshortener
- Owner: evgeniy-dammer
- Created: 2022-04-14T11:58:19.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2022-04-14T11:58:22.000Z (about 4 years ago)
- Last Synced: 2025-06-02T14:59:32.859Z (about 1 year ago)
- Topics: go, golang, gophercises, url-shortener, urlshortener
- Language: Go
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# "URL Shortener" exercise from Gophercises (by Jon Calhoun)
Website: https://gophercises.com
GitHub: https://github.com/gophercises
YouTube: https://www.youtube.com/playlist?list=PLVEltXlEeWglGINo25GxVfvSSylLVg4r1
## Task
The goal of this exercise is to create an `http.Handler` that will look at the path of any incoming web request and determine if it should redirect the user to a new page, much like URL shortener would.
For instance, if we have a redirect setup for `/dogs` to `https://www.somesite.com/a-story-about-dogs` we would look for any incoming web requests with the path `/dogs` and redirect them.
To complete this exercises you will need to implement the stubbed out methods in `handler.go`. There are a good bit of comments explaining what each method should do, and there is also a `main.go` source file that uses the package to help you test your code and get an idea of what your program should be doing.
Focus on parsing the YAML using the [gopkg.in/yaml.v2](https://godoc.org/gopkg.in/yaml.v2) package.
After you get the YAML parsing down, try to convert the data into a map and then use the MapHandler to finish the YAMLHandler implementation. Eg you might end up with some code like this:
```go
func YAMLHandler(yaml []byte, fallback http.Handler) (http.HandlerFunc, error) {
parsedYaml, err := parseYAML(yaml)
if err != nil {
return nil, err
}
pathMap := buildMap(parsedYaml)
return MapHandler(pathMap, fallback), nil
}
```
But in order for this to work you will need to create functions like `parseYAML` and `buildMap` on your own. This should give you ample experience working with YAML data.