-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
64 lines (50 loc) · 1.58 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
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"net/http/httputil"
"net/url"
"path/filepath"
"log"
)
const yuyuteiURL = "https://yuyu-tei.jp/"
const hoTcURL = "https://www.heartofthecards.com/code/cardlist.html?card=WS_"
const yuyuteiBase = "https://yuyu-tei.jp/game_ws"
var yytMap = map[string]Card{}
var plugins = []plugin{}
// New proxy
func New(target string) *Prox {
url, _ := url.Parse(target)
// you should handle error on parsing
return &Prox{target: url, proxy: httputil.NewSingleHostReverseProxy(url)}
}
func (p *Prox) handle(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-GoProxy", "GoProxy")
// call to magic method from ReverseProxy object
p.proxy.ServeHTTP(w, r)
}
func main() {
proxy := New("http://localhost:8081")
yytInfosData, yytErr := ioutil.ReadFile(filepath.Join("static", "yyt_infos.json"))
if yytErr != nil {
fmt.Println(yytErr)
}
json.Unmarshal(yytInfosData, &yytMap)
plugins = append(plugins, encoredecks{})
plugins = append(plugins, wstcg{})
plugins = append(plugins, decklog{})
http.HandleFunc("/", proxy.handle)
http.HandleFunc("/views/translationimages", getTranslationHotC)
http.HandleFunc("/views/cardimages", cardimages)
http.HandleFunc("/views/estimateprice", estimatePrice)
http.HandleFunc("/views/searchcards", searchcards)
http.HandleFunc("/views/exportcockatrice", exportcockatrice)
http.HandleFunc("/views/cache", cache)
http.HandleFunc("/static/", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, r.URL.Path[1:])
})
log.Print("Ready at 8010!")
http.ListenAndServe(":8010", nil)
}