Skip to content

Commit

Permalink
First version of golang middleware with mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
bertop89 committed Oct 4, 2015
1 parent 2f3e8be commit 7f03085
Show file tree
Hide file tree
Showing 8 changed files with 393 additions and 0 deletions.
Binary file added pkg/linux_amd64/github.com/codegangsta/inject.a
Binary file not shown.
Binary file added pkg/linux_amd64/github.com/go-martini/martini.a
Binary file not shown.
63 changes: 63 additions & 0 deletions responses/box_office.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"movies": [{
"id": "770687943",
"title": "Harry Potter and the Deathly Hallows - Part 2",
"year": 2011,
"mpaa_rating": "PG-13",
"runtime": 130,
"critics_consensus": "Thrilling, powerfully acted, and visually dazzling, Deathly Hallows Part II brings the Harry Potter franchise to a satisfying -- and suitably magical -- conclusion.",
"release_dates": {"theater": "2011-07-15"},
"ratings": {
"critics_rating": "Certified Fresh",
"critics_score": 97,
"audience_rating": "Upright",
"audience_score": 93
},
"synopsis": "Harry Potter and the Deathly Hallows - Part 2, is the final adventure in the Harry Potter film series. The much-anticipated motion picture event is the second of two full-length parts. In the epic finale, the battle between the good and evil forces of the wizarding world escalates into an all-out war. The stakes have never been higher and no one is safe. But it is Harry Potter who may be called upon to make the ultimate sacrifice as he draws closer to the climactic showdown with Lord Voldemort. It all ends here. -- (C) Warner Bros",
"posters": {
"thumbnail": "http://content8.flixster.com/movie/11/15/86/11158674_tmb.jpg",
"profile": "http://content8.flixster.com/movie/11/15/86/11158674_tmb.jpg",
"detailed": "http://content8.flixster.com/movie/11/15/86/11158674_tmb.jpg",
"original": "http://content8.flixster.com/movie/11/15/86/11158674_tmb.jpg"
},
"abridged_cast": [
{
"name": "Daniel Radcliffe",
"characters": ["Harry Potter"]
},
{
"name": "Rupert Grint",
"characters": [
"Ron Weasley",
"Ron Wesley"
]
},
{
"name": "Emma Watson",
"characters": ["Hermione Granger"]
},
{
"name": "Helena Bonham Carter",
"characters": ["Bellatrix Lestrange"]
},
{
"name": "Ralph Fiennes",
"characters": ["Lord Voldemort"]
}
],
"alternate_ids": {"imdb": "1201607"},
"links": {
"self": "http://api.rottentomatoes.com/api/public/v1.0/movies/770687943.json",
"alternate": "http://www.rottentomatoes.com/m/harry_potter_and_the_deathly_hallows_part_2/",
"cast": "http://api.rottentomatoes.com/api/public/v1.0/movies/770687943/cast.json",
"clips": "http://api.rottentomatoes.com/api/public/v1.0/movies/770687943/clips.json",
"reviews": "http://api.rottentomatoes.com/api/public/v1.0/movies/770687943/reviews.json",
"similar": "http://api.rottentomatoes.com/api/public/v1.0/movies/770687943/similar.json"
}
}],
"links": {
"self": "http://api.rottentomatoes.com/api/public/v1.0/lists/movies/box_office.json?limit=1&country=us",
"alternate": "http://www.rottentomatoes.com/movie/box_office.php"
},
"link_template": "http://api.rottentomatoes.com/api/public/v1.0/lists/movies/box_office.json?limit={num-results}&country={country-code}"
}
68 changes: 68 additions & 0 deletions responses/upcoming.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"total": 29,
"movies": [{
"id": "770863875",
"title": "Cowboys and Aliens",
"year": 2011,
"mpaa_rating": "PG-13",
"runtime": "",
"release_dates": {"theater": "2011-07-29"},
"ratings": {
"critics_score": -1,
"audience_score": 94
},
"synopsis": "1875. New Mexico Territory. A stranger (Craig) with no memory of his past stumbles into the hard desert town of Absolution. What he discovers is that the people of Absolution don't welcome strangers, and nobody makes a move on its streets unless ordered to do so by the iron-fisted Colonel Dolarhyde (Ford). It's a town that lives in fear. But Absolution is about to experience fear it can scarcely comprehend as the desolate city is attacked by marauders from the sky. Now, the stranger they rejected is their only hope for salvation. As this gunslinger slowly starts to remember who he is and where he's been, he realizes he holds a secret that could give the town a fighting chance against the alien force. -- (C) Official Site",
"posters": {
"thumbnail": "http://content8.flixster.com/movie/11/15/42/11154270_tmb.jpg",
"profile": "http://content8.flixster.com/movie/11/15/42/11154270_tmb.jpg",
"detailed": "http://content8.flixster.com/movie/11/15/42/11154270_tmb.jpg",
"original": "http://content8.flixster.com/movie/11/15/42/11154270_tmb.jpg"
},
"abridged_cast": [
{
"name": "Daniel Craig",
"characters": ["Zeke Jackson"]
},
{
"name": "Olivia Wilde",
"characters": [
"Ella",
"Ella Swenson"
]
},
{
"name": "Harrison Ford",
"characters": [
"Colonel Dolarhyde",
"Woodrow Dolarhyde"
]
},
{
"name": "Sam Rockwell",
"characters": ["Doc"]
},
{
"name": "Paul Dano",
"characters": [
"Percy",
"Percy Dollarhyde"
]
}
],
"alternate_ids": {"imdb": "0409847"},
"links": {
"self": "http://api.rottentomatoes.com/api/public/v1.0/movies/770863875.json",
"alternate": "http://www.rottentomatoes.com/m/cowboys_and_aliens/",
"cast": "http://api.rottentomatoes.com/api/public/v1.0/movies/770863875/cast.json",
"clips": "http://api.rottentomatoes.com/api/public/v1.0/movies/770863875/clips.json",
"reviews": "http://api.rottentomatoes.com/api/public/v1.0/movies/770863875/reviews.json",
"similar": "http://api.rottentomatoes.com/api/public/v1.0/movies/770863875/similar.json"
}
}],
"links": {
"self": "http://api.rottentomatoes.com/api/public/v1.0/lists/movies/upcoming.json?page_limit=1&country=us&page=1",
"next": "http://api.rottentomatoes.com/api/public/v1.0/lists/movies/upcoming.json?page_limit=1&country=us&page=2",
"alternate": "http://www.rottentomatoes.com/movie/upcoming.php"
},
"link_template": "http://api.rottentomatoes.com/api/public/v1.0/lists/movies/upcoming.json?page_limit={results_per_page}&page={page_number}&country={country-code}"
}
50 changes: 50 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package main

import (
"net/http"
"github.com/go-martini/martini"
"io/ioutil"
)

func main() {
m := martini.Classic()

bo,up := read_files()

m.Get("/box_office", func(writer http.ResponseWriter) string {
writer.Header().Set("Content-Type", "application/json")
return bo
})

m.Get("/upcoming_movies", func(writer http.ResponseWriter) string {
writer.Header().Set("Content-Type", "application/json")
return up
})

m.Get("/top_dvds", func() string {
return "Top DVDs"
})

m.Get("/upcoming_dvds", func() string {
return "Upcoming DVDs"
})



m.Run()
}

func check(e error) {
if e != nil {
panic(e)
}
}

func read_files() (string,string) {
bo, err := ioutil.ReadFile("responses/box_office.json")
check(err)
up, err := ioutil.ReadFile("responses/upcoming.json")
check(err)

return string(bo),string(up)
}
210 changes: 210 additions & 0 deletions server.sublime-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
{
"auto_complete":
{
"selected_items":
[
[
"sor",
"sorted_dic"
],
[
"tw",
"tweet"
],
[
"ha",
"hashtag"
],
[
"h",
"hashtag"
],
[
"term",
"terms"
],
[
"twe",
"tweet"
],
[
"s",
"score"
],
[
"sent",
"sent_dic"
],
[
"load",
"load_tweets"
]
]
},
"buffers":
[
],
"build_system": "",
"build_system_choices":
[
],
"build_varint": "",
"command_palette":
{
"height": 0.0,
"last_filter": "",
"selected_items":
[
],
"width": 0.0
},
"console":
{
"height": 0.0,
"history":
[
]
},
"distraction_free":
{
"menu_visible": true,
"show_minimap": false,
"show_open_files": false,
"show_tabs": false,
"side_bar_visible": false,
"status_bar_visible": false
},
"file_history":
[
"/home/alberto/Documentos/datavis/datasci_course_materials/assignment1/AFINN-111.txt",
"/home/alberto/Documentos/datavis/datasci_course_materials/assignment1/output.txt",
"/home/alberto/Documentos/datavis/datasci_course_materials/assignment1/top_ten.py",
"/home/alberto/Documentos/datavis/datasci_course_materials/assignment1/term_sentiment.py",
"/home/alberto/Documentos/datavis/datasci_course_materials/assignment1/tweet_sentiment.py",
"/home/alberto/Documentos/datavis/datasci_course_materials/assignment1/twitterstream.py",
"/home/alberto/Documentos/d3.js/index.html"
],
"find":
{
"height": 23.0
},
"find_in_files":
{
"height": 0.0,
"where_history":
[
]
},
"find_state":
{
"case_sensitive": false,
"find_history":
[
"hasht",
"text\":",
"text"
],
"highlight": true,
"in_selection": false,
"preserve_case": false,
"regex": false,
"replace_history":
[
],
"reverse": false,
"show_context": true,
"use_buffer2": true,
"whole_word": false,
"wrap": true
},
"groups":
[
{
"sheets":
[
]
}
],
"incremental_find":
{
"height": 23.0
},
"input":
{
"height": 0.0
},
"layout":
{
"cells":
[
[
0,
0,
1,
1
]
],
"cols":
[
0.0,
1.0
],
"rows":
[
0.0,
1.0
]
},
"menu_visible": true,
"output.find_results":
{
"height": 0.0
},
"pinned_build_system": "",
"project": "server.sublime-project",
"replace":
{
"height": 42.0
},
"save_all_on_build": true,
"select_file":
{
"height": 0.0,
"last_filter": "",
"selected_items":
[
],
"width": 0.0
},
"select_project":
{
"height": 0.0,
"last_filter": "",
"selected_items":
[
],
"width": 0.0
},
"select_symbol":
{
"height": 0.0,
"last_filter": "",
"selected_items":
[
],
"width": 0.0
},
"selected_group": 0,
"settings":
{
},
"show_minimap": true,
"show_open_files": false,
"show_tabs": true,
"side_bar_visible": true,
"side_bar_width": 150.0,
"status_bar_visible": true,
"template_settings":
{
}
}
1 change: 1 addition & 0 deletions src/github.com/codegangsta/inject
Submodule inject added at 33e0aa
Loading

0 comments on commit 7f03085

Please sign in to comment.