-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
160 lines (144 loc) · 5.84 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package main
import (
"database/sql"
"encoding/json"
"fmt"
"strings"
_ "github.com/lib/pq"
"github.com/skratchdot/open-golang/open"
"net/http"
"os"
"time"
)
var DB_USERNAME string
// var DB_PASSWORD string
var DB_DBNAME string
var DB_SSLMODE string
func main() {
port := os.Getenv("PORT")
if port == "" { port = "3000" }
DB_USERNAME = os.Getenv("FRP_DB_USERNAME")
if DB_USERNAME == "" { DB_USERNAME = "thrivesmart1" }
// DB_PASSWORD = os.Getenv("FRP_DB_PASSWORD")
DB_DBNAME = os.Getenv("FRP_DB_DBNAME")
if DB_DBNAME == "" { DB_DBNAME = "frp" }
DB_SSLMODE = os.Getenv("FRP_DB_SSLMODE")
if DB_SSLMODE == "" { DB_SSLMODE = "disable" }
http.HandleFunc("/", hello)
http.HandleFunc("/yahoo", yhoo)
http.HandleFunc("/update-library", updates)
fmt.Println("listening on port " + port + "...")
err := http.ListenAndServe(":"+port, nil)
if err != nil {
panic(err)
}
}
type Episode struct {
Id int64 `json:"id"`
SeriesId int64 `json:"series_id"`
Title string `json:"title"`
Year int64 `json:"year"`
Rated string `json:"rated"`
Released time.Time `json:"released"`
RuntimeMinutes int64 `json:"runtime_minutes"`
Plot string `json:"plot"`
Language string `json:"language"`
PosterUrl string `json:"poster_url"`
TomameterRating int64 `json:"tomameter_rating"`
TomameterVoteCount int64 `json:"tomameter_vote_count"`
Imdbid string `json:"imdbid"`
ImdbRating int64 `json:"imdb_rating"`
ImdbVoteCount int64 `json:"imdb_vote_count"`
GenresJson string `json:"genres_json"`
DirectorsJson string `json:"directors_json"`
WritersJson string `json:"writers_json"`
ActorsJson string `json:"actors_json"`
CountriesJson string `json:"countries_json"`
SubtitleLanguagesJson string `json:"subtitle_languages_json"`
StreamingUrlsJson string `json:"streaming_urls_json"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type Movie struct {
Id int64 `json:"id"`
Title string `json:"title"`
Year int64 `json:"year"`
Rated string `json:"rated"`
Released time.Time `json:"released"`
RuntimeMinutes int64 `json:"runtime_minutes"`
Plot string `json:"plot"`
Language string `json:"language"`
PosterUrl string `json:"poster_url"`
TomameterRating int64 `json:"tomameter_rating"`
TomameterVoteCount int64 `json:"tomameter_vote_count"`
Imdbid string `json:"imdbid"`
ImdbRating int64 `json:"imdb_rating"`
ImdbVoteCount int64 `json:"imdb_vote_count"`
GenresJson string `json:"genres_json"`
DirectorsJson string `json:"directors_json"`
WritersJson string `json:"writers_json"`
ActorsJson string `json:"actors_json"`
CountriesJson string `json:"countries_json"`
SubtitleLanguagesJson string `json:"subtitle_languages_json"`
StreamingUrlsJson string `json:"streaming_urls_json"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type Series struct {
Id int64 `json:"id"`
Title string `json:"title"`
StartYear int64 `json:"start_year"`
EndYear int64 `json:"end_year"`
Rated string `json:"rated"`
Released time.Time `json:"released"`
Plot string `json:"plot"`
Language string `json:"language"`
PosterUrl string `json:"poster_url"`
TomameterRating int64 `json:"tomameter_rating"`
TomameterVoteCount int64 `json:"tomameter_vote_count"`
Imdbid string `json:"imdbid"`
ImdbRating int64 `json:"imdb_rating"`
ImdbVoteCount int64 `json:"imdb_vote_count"`
GenresJson string `json:"genres_json"`
DirectorsJson string `json:"directors_json"`
WritersJson string `json:"writers_json"`
ActorsJson string `json:"actors_json"`
CountriesJson string `json:"countries_json"`
SubtitleLanguagesJson string `json:"subtitle_languages_json"`
StreamingUrlsJson string `json:"streaming_urls_json"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func hello(res http.ResponseWriter, req *http.Request) {
fmt.Fprintln(res, "Hello, world!")
}
func yhoo(res http.ResponseWriter, req *http.Request) {
open.RunWith("http://www.yahoo.com/", "safari")
}
func updates(res http.ResponseWriter, req *http.Request) {
var err error
connector := []string{"user=", DB_USERNAME, " dbname=", DB_DBNAME, " sslmode=", DB_SSLMODE};
db, err := sql.Open("postgres", strings.Join(connector, ""))
if err != nil { http.Error(res, err.Error(), 500); return }
kind := req.FormValue("kind")
js := req.FormValue("json")
var episode Episode
var movie Movie
var series Series
if kind == "episode" {
err = json.Unmarshal([]byte(js), &episode)
if err != nil { http.Error(res, err.Error(), 500); return }
} else if kind == "movie" {
err = json.Unmarshal([]byte(js), &movie)
if err != nil { http.Error(res, err.Error(), 500); return }
} else if kind == "series" {
err = json.Unmarshal([]byte(js), &series)
if err != nil { http.Error(res, err.Error(), 500); return }
} else {
http.Error(res, "Missing `kind` parameter.", 422)
return
}
age := 21
_, err = db.Query("SELECT title FROM movies WHERE imdbid = $1", age)
fmt.Fprintln(res, err)
}