Created
November 30, 2018 17:23
-
-
Save reedobrien/664a19554499f39156fe1a1e9e69aa6c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "net/http" | |
func main() { | |
plexHandler := server.MustMovieHandler(plex.Must(plexURL)) | |
umsHandler := server.MustMovieHandler(ums.Must(umsURL)) | |
s := server.MustServer([]http.Handler{plexHandler, umsHandler}) | |
s.ListenAndServeTLS... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package movie | |
type Finder interface { | |
Find(string) (Movie, error) | |
} | |
type Movie struct { | |
Title string | |
Year int | |
Director Person | |
} | |
type Person struct { | |
GivenName string | |
Surname string | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package plex | |
import ( | |
"log" | |
"net/url" | |
"github.com/reedobrien/mms/movie" | |
) | |
// Must ... | |
func Must(ep url.Url) { | |
conn, err := plexclient.New(u.String()) | |
if err != nil { | |
log.Fatalln("boom!") | |
} | |
return plex{conn: conn} | |
} | |
type plex struct { | |
conn plexclient.Client | |
} | |
// Find ... | |
func (pc *plexclient) Find(s string) (movie.Movie, error) { | |
result, err := pc.conn.GetTitle(s) | |
if err != nil { | |
return movie.Movie{}, err | |
} | |
return movieFromResult(result), nil | |
} | |
func movieFromResult(r plexclient.Result) movie.Movie { | |
return movie.Movie{ | |
Title: r.Title, | |
Year: int(r.Year), | |
Director: Person{ | |
GivenName: r.DirectorFName, | |
Surname: r.DirectorLName, | |
}, | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ums | |
import ( | |
"log" | |
"net/url" | |
"github.com/reedobrien/mms/movie" | |
) | |
// MustUMS ... | |
func Must(ep url.Url) { | |
conn, err := umsclient.New(u.String()) | |
if err != nil { | |
log.Fatalln("boom!") | |
} | |
return ums{conn: conn} | |
} | |
type ums struct { | |
conn umsclient.Client | |
} | |
// Find ... | |
func (pc *umsclient) Find(s string) (movie.Movie, error) { | |
result, err := pc.conn.GetTitle(s) | |
if err != nil { | |
return movie.Movie{}, err | |
} | |
return movieFromResult(result), nil | |
} | |
func movieFromResult(r umsclient.Result) movie.Movie { | |
return movie.Movie{ | |
Title: r.Title, | |
Year: int(r.Year), | |
Director: Person{ | |
GivenName: r.DirectorFirst, | |
Surname: r.DirectorLast, | |
}, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment