-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
74 lines (58 loc) · 1.37 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
package main
import (
"database/sql"
"fmt"
"io/ioutil"
"net/http"
"os"
"github.com/getyoti/yoti-go-sdk"
"github.com/gorilla/mux"
_ "github.com/go-sql-driver/mysql"
)
const (
// TODO: for deploy, those arguments should get from os.Getenv()
appID = "<Yoti AppID>"
sdkID = "<Yoti SDKID>"
dbConn = "<MySQL Connection>"
port = "8080"
sdkKeyFile = "key.pem"
htmlTemplte = "index.html"
anonymousFile = "anonymous.png"
sessionID = "yoti"
sessionProfileKey = "profile"
)
var store = newCookieStore()
func yotiClient(skdID, keyFile string) (*yoti.Client, error) {
key, err := ioutil.ReadFile(keyFile)
if err != nil {
return nil, err
}
client := &yoti.Client{
SdkID: skdID,
Key: key,
}
return client, nil
}
func main() {
// TODO: Log error to os.StdErr, no panic
db, err := sql.Open("mysql", dbConn)
if err != nil {
panic(err)
}
if err := db.Ping(); err != nil {
panic(err)
}
c, err := yotiClient(sdkID, sdkKeyFile)
if err != nil {
panic(err)
}
r := mux.NewRouter()
r.Handle("/", mainHandler(db))
r.Handle("/comments", postHandler(db))
r.Handle("/callback", callbackHandler(c, db))
r.PathPrefix("/images/").Handler(http.StripPrefix("/images/", imageHandler(db, anonymousFile)))
fmt.Fprintf(os.Stdout, "Try listening...:%s", port)
if err := http.ListenAndServe(":"+port, recoveryHandler(true, r)); err != nil {
panic(err)
}
}