All Projects → gophercises → urlshort

gophercises / urlshort

Licence: other
Ex 2 - Create an http.Handler that forwards paths to other URLs

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to urlshort

Reports.JS
Stimulsoft Reports.JS is a reporting tool for Node.js and JavaScript applications.
Stars: ✭ 33 (-71.05%)
Mutual labels:  maps
ilong
轻量级跨平台瓦片地图库,大部分算法来自QMapControl,就想练手的。。。因为需要轻量级跨平台的,所以只能先用SQLite数据库。。。
Stars: ✭ 24 (-78.95%)
Mutual labels:  maps
CabanasRD
No description or website provided.
Stars: ✭ 14 (-87.72%)
Mutual labels:  maps
codemagic-sample-projects
A collection of sample apps built with Codemagic CI/CD. Please see the codemagic.yaml file for a sample workflow configuration.
Stars: ✭ 82 (-28.07%)
Mutual labels:  yaml
trackanimation
Track Animation is a Python 2 and 3 library that provides an easy and user-adjustable way of creating visualizations from GPS data.
Stars: ✭ 74 (-35.09%)
Mutual labels:  maps
MapDownloader
Map downloader based on GMap.NET
Stars: ✭ 226 (+98.25%)
Mutual labels:  maps
vscode-yaml-sort
This VS Code extension exposes the possibility to sort, format and validate yaml files.
Stars: ✭ 25 (-78.07%)
Mutual labels:  yaml
stein
A linter for config files with a customizable rule set
Stars: ✭ 92 (-19.3%)
Mutual labels:  yaml
exenv
Exenv makes loading environment variables from external sources easy.
Stars: ✭ 35 (-69.3%)
Mutual labels:  yaml
yamlinc
Compose multiple YAML files into one with $include tag. Split Swagger/OpenAPI into multiple YAML files.
Stars: ✭ 103 (-9.65%)
Mutual labels:  yaml
cfg-rs
A Configuration Library for Rust Applications
Stars: ✭ 18 (-84.21%)
Mutual labels:  yaml
ufw
A minimalist framework for rapid server side applications prototyping in C++ with dependency injection support.
Stars: ✭ 19 (-83.33%)
Mutual labels:  yaml
timetable
Bus Timetable app React Native
Stars: ✭ 61 (-46.49%)
Mutual labels:  maps
smacha
SMACHA is a meta-scripting, templating, and code generation engine for rapid prototyping of ROS SMACH state machines.
Stars: ✭ 15 (-86.84%)
Mutual labels:  yaml
Codeigniter3-absen-digital
Sistem Absensi Online dengan framework codeigniter 3
Stars: ✭ 33 (-71.05%)
Mutual labels:  maps
havener
/ˈheɪvənə/ - Think of it as a swiss army knife for Kubernetes tasks
Stars: ✭ 296 (+159.65%)
Mutual labels:  yaml
polyglot-jekyll
Plugin-free multilanguage Jekyll websites
Stars: ✭ 46 (-59.65%)
Mutual labels:  yaml
Euclid
Great-circle mathematics helper library for platforms using Swift -
Stars: ✭ 46 (-59.65%)
Mutual labels:  maps
jpn-atlas
TopoJSONフォーマットの日本の国、都道府県、市区町村の境界データ。Japanese municipality and prefecture boundary data in topojson format.
Stars: ✭ 17 (-85.09%)
Mutual labels:  maps
check-geojson
a checker for the geojson format. goes beyond a schema, checking semantics and producing character-level warnings.
Stars: ✭ 36 (-68.42%)
Mutual labels:  maps

Exercise #2: URL Shortener

exercise status: released

Exercise details

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/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.

I suggest first commenting out all of the code in main.go related to the YAMLHandler function and focusing on implementing the MapHandler function first.

Once you have that working, focus on parsing the YAML using the gopkg.in/yaml.v2 package. Note: You will need to go get this package if you don't have it already.

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:

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.

Bonus

As a bonus exercises you can also...

  1. Update the main/main.go source file to accept a YAML file as a flag and then load the YAML from a file rather than from a string.
  2. Build a JSONHandler that serves the same purpose, but reads from JSON data.
  3. Build a Handler that doesn't read from a map but instead reads from a database. Whether you use BoltDB, SQL, or something else is entirely up to you.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].