formatting and applying lint

This commit is contained in:
Christopher Herrera 2014-09-28 14:07:05 -04:00
parent 10fc92c08d
commit d3189fa436
2 changed files with 22 additions and 23 deletions

View file

@ -33,4 +33,5 @@ See the project documentation to see the Response Objects and stuff
Project Documentation Project Documentation
--------------------- ---------------------
The automatically generated documentation can be found in [godocs](http://godoc.org/github.com/eefret/go-imdb) The automatically generated documentation can be found in godocs.
[![GoDoc](https://godoc.org/github.com/eefret/go-imdb?status.svg)](https://godoc.org/github.com/eefret/go-imdb)

42
imdb.go
View file

@ -20,7 +20,6 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
//"log"
"net/http" "net/http"
"strings" "strings"
) )
@ -28,7 +27,7 @@ import (
//======================================================================= //=======================================================================
// Const // Const
//======================================================================= //=======================================================================
const baseUrl string = "http://www.omdbapi.com/?" const baseURL string = "http://www.omdbapi.com/?"
const plot string = "full" const plot string = "full"
const tomatoes string = "true" const tomatoes string = "true"
@ -40,22 +39,22 @@ const tomatoes string = "true"
// Structs // Structs
//======================================================================= //=======================================================================
//Type for the Search Response //SearchResult is the type for the search results
type SearchResult struct { type SearchResult struct {
Title string Title string
Year string Year string
ImdbId string ImdbID string
Type string Type string
} }
//Type that respond Search //SearchResponse is the struct of the response in a search
type SearchResponse struct { type SearchResponse struct {
Search []SearchResult Search []SearchResult
Response string Response string
Error string Error string
} }
//Type for searching a specific movie //MovieResult is the result struct of an specific movie search
type MovieResult struct { type MovieResult struct {
Title string Title string
Year string Year string
@ -98,9 +97,9 @@ type MovieResult struct {
// Funcs // Funcs
//======================================================================= //=======================================================================
//Search for movies given a Title and year, Year is optional you can pass nil //SearchMovies search for movies given a Title and year, Year is optional you can pass nil
func SearchMovies(title string, year string) (*SearchResponse, error) { func SearchMovies(title string, year string) (*SearchResponse, error) {
resp, err := omdbApiRequest(title, "", "", year) resp, err := omdbAPIRequest(title, "", "", year)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -117,9 +116,9 @@ func SearchMovies(title string, year string) (*SearchResponse, error) {
return r, nil return r, nil
} }
//returns a MovieResult given Title //GetMovieByTitle returns a MovieResult given Title
func GetMovieByTitle(title string, year string) (*MovieResult, error) { func GetMovieByTitle(title string, year string) (*MovieResult, error) {
resp, err := omdbApiRequest("", "", title, year) resp, err := omdbAPIRequest("", "", title, year)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -135,9 +134,9 @@ func GetMovieByTitle(title string, year string) (*MovieResult, error) {
return r, nil return r, nil
} }
// returns a MovieResult given a ImdbId ex:"tt2015381" //GetMovieByImdbID returns a MovieResult given a ImdbID ex:"tt2015381"
func GetMovieByImdbId(id string) (*MovieResult, error) { func GetMovieByImdbID(id string) (*MovieResult, error) {
resp, err := omdbApiRequest("", id, "", "") resp, err := omdbAPIRequest("", id, "", "")
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -153,21 +152,21 @@ func GetMovieByImdbId(id string) (*MovieResult, error) {
return r, nil return r, nil
} }
func omdbApiRequest(s string, i string, t string, y string) (resp *http.Response, err error) { func omdbAPIRequest(s string, i string, t string, y string) (resp *http.Response, err error) {
//s = Search Parameter, if this is != nil then its a searchMovies //s = Search Parameter, if this is != nil then its a searchMovies
//i = Id Parameter, if this is != nil then its a getMovieByImdbId //i = Id Parameter, if this is != nil then its a getMovieByImdbID
//t = Title Parameter, if this is != nil then its a getMovieByTitle //t = Title Parameter, if this is != nil then its a getMovieByTitle
//y = Year Parameter, Optional data for s and t search //y = Year Parameter, Optional data for s and t search
//var res http.Response //var res http.Response
var url string var url string
if s != "" { if s != "" {
s = strings.Replace(s, " ", "%20", -1) s = strings.Replace(s, " ", "%20", -1)
url = fmt.Sprintf(baseUrl+"s=%s&y=%s", s, y) url = fmt.Sprintf(baseURL+"s=%s&y=%s", s, y)
} else if i != "" { } else if i != "" {
url = fmt.Sprintf(baseUrl+"i=%s&plot=%s&tomatoes=%s", i, plot, tomatoes) url = fmt.Sprintf(baseURL+"i=%s&plot=%s&tomatoes=%s", i, plot, tomatoes)
} else if t != "" { } else if t != "" {
t = strings.Replace(t, " ", "%20", -1) t = strings.Replace(t, " ", "%20", -1)
url = fmt.Sprintf(baseUrl+"t=%s&plot=%s&tomatoes=%s&y=%s", t, plot, tomatoes, y) url = fmt.Sprintf(baseURL+"t=%s&plot=%s&tomatoes=%s&y=%s", t, plot, tomatoes, y)
} else { } else {
return nil, errors.New("Invalid Request") return nil, errors.New("Invalid Request")
} }
@ -182,10 +181,9 @@ func omdbApiRequest(s string, i string, t string, y string) (resp *http.Response
func checkErrorStatus(status int) error { func checkErrorStatus(status int) error {
if status != 200 { if status != 200 {
return errors.New(fmt.Sprintf("Status Code %d received from IMDB", status)) return fmt.Errorf("Status Code %d received from IMDB", status)
} else {
return nil
} }
return nil
} }
//Stringer Interface for MovieResult //Stringer Interface for MovieResult
@ -195,5 +193,5 @@ func (mr MovieResult) String() string {
//Stringer Interface for SearchResult //Stringer Interface for SearchResult
func (sr SearchResult) String() string { func (sr SearchResult) String() string {
return fmt.Sprintf("#%s: %s (%s) Type: %s", sr.ImdbId, sr.Title, sr.Year, sr.Type) return fmt.Sprintf("#%s: %s (%s) Type: %s", sr.ImdbID, sr.Title, sr.Year, sr.Type)
} }