You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.9 KiB

  1. travel audience Go challenge
  2. ============================
  3. Task
  4. ----
  5. Write an HTTP service that exposes an endpoint "/numbers". This endpoint receives a list of URLs
  6. though GET query parameters. The parameter in use is called "u". It can appear
  7. more than once.
  8. http://yourserver:8080/numbers?u=http://example.com/primes&u=http://foobar.com/fibo
  9. When the /numbers is called, your service shall retrieve each of these URLs if
  10. they turn out to be syntactically valid URLs. Each URL will return a JSON data
  11. structure that looks like this:
  12. { "numbers": [ 1, 2, 3, 5, 8, 13 ] }
  13. The JSON data structure will contain an object with a key named "numbers", and
  14. a value that is a list of integers. After retrieving each of these URLs, the
  15. service shall merge the integers coming from all URLs, sort them in ascending
  16. order, and make sure that each integer only appears once in the result. The
  17. endpoint shall then return a JSON data structure like in the example above with
  18. the result as the list of integers.
  19. The endpoint needs to return the result as quickly as possible, but always
  20. within 500 milliseconds. It needs to be able to deal with error conditions when
  21. retrieving the URLs. If a URL takes too long to respond, it must be ignored. It
  22. is valid to return an empty list as result only if all URLs returned errors or
  23. took too long to respond.
  24. Example
  25. -------
  26. The service receives an HTTP request:
  27. >>> GET /numbers?u=http://example.com/primes&u=http://foobar.com/fibo HTTP/1.0
  28. It then retrieves the URLs specified as parameters.
  29. The first URL returns this response:
  30. >>> GET /primes HTTP/1.0
  31. >>> Host: example.com
  32. >>>
  33. <<< HTTP/1.0 200 OK
  34. <<< Content-Type: application/json
  35. <<< Content-Length: 34
  36. <<<
  37. <<< { "number": [ 2, 3, 5, 7, 11, 13 ] }
  38. The second URL returns this response:
  39. >>> GET /fibo HTTP/1.0
  40. >>> Host: foobar.com
  41. >>>
  42. <<< HTTP/1.0 200 OK
  43. <<< Content-Type: application/json
  44. <<< Content-Length: 40
  45. <<<
  46. <<< { "number": [ 1, 1, 2, 3, 5, 8, 13, 21 ] }
  47. The service then calculates the result and returns it.
  48. <<< HTTP/1.0 200 OK
  49. <<< Content-Type: application/json
  50. <<< Content-Length: 44
  51. <<<
  52. <<< { "number": [ 1, 2, 3, 5, 7, 8, 11, 13, 21 ] }
  53. Completion Conditions
  54. ---------------------
  55. Solve the task described above using Go. Only use what's provided in the Go
  56. standard library. The resulting program must run stand-alone with no other
  57. dependencies than the Go compiler.
  58. Document your source code, both using comments and in a separate text file that
  59. describes the intentions and rationale behind your solution. Also write down
  60. any ambiguities that you see in the task description, and describe you how you
  61. interpreted them and why. If applicable, write automated tests for your code.
  62. For testing purposes, you will be provided with an example server that, when
  63. run, listens on port 8090 and provides the endpoints /primes, /fibo, /odd and
  64. /rand.
  65. Please return your working solution within 7 days of receiving the challenge.