forked from isuncoin/ifundgate
/
main.go
73 lines (63 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
65
66
67
68
69
70
71
72
73
//
//
//
package main
import (
"io"
"net/http"
"os"
"github.com/astaxie/beego"
"github.com/astaxie/beego/context"
"github.com/astaxie/beego/plugins/cors"
"github.com/wangch/glog"
"github.com/wangch/icloudfund/controllers"
_ "github.com/wangch/icloudfund/routers"
)
func init() {
beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
AllowOrigins: []string{"*"},
AllowMethods: []string{"GET", "PUT", "PATCH"},
AllowHeaders: []string{"Origin"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
}))
beego.EnableHttpListen = false
beego.EnableHttpTLS = true
beego.HttpsPort = 443
beego.HttpCertFile = "cert.pem"
beego.HttpKeyFile = "key.pem"
beego.SessionOn = true
beego.SetStaticPath("/css", "static/css")
beego.SetStaticPath("/js", "static/js")
beego.SetStaticPath("/img", "static/img")
beego.SetStaticPath("/fonts", "static/fonts")
beego.SetStaticPath("/favicon.png", "./favicon.png")
}
func main() {
glog.SetLogDirs(".")
glog.SetLogToStderr(true)
conf := controllers.Gconf
beego.Get("/federation", func(ctx *context.Context) {
federation(ctx, conf)
})
beego.Get("/ripple.txt", func(ctx *context.Context) {
f, err := os.Open("ripple.txt")
if err != nil {
glog.Fatal(err)
}
io.Copy(ctx.ResponseWriter, f)
f.Close()
})
beego.Get("/quote", func(ctx *context.Context) {
u := "http://" + conf.Host + "/api/quote?" + ctx.Request.URL.RawQuery
glog.Infoln(u)
r, err := http.Get(u)
if err != nil {
glog.Errorln(err)
return
}
io.Copy(ctx.ResponseWriter, r.Body)
r.Body.Close()
})
beego.Run()
}