|
- package main
-
- import (
- "log"
- "net/http"
- "os"
- "text/template"
- "time"
- )
-
- func main() {
- db.h = nil //make sure it's in proper state.
-
- //setup log file
- filename := "logs/rpn.superforex." + time.Now().Format("2006-01-02-15-04-06") + ".log"
- f, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
- if err != nil {
- log.Fatalf("Error opening file: %v", err)
- }
- defer f.Close()
- log.SetOutput(f)
-
- //Read Config
- readConfig()
- //readConfigForTest()
-
- //setup http handler
- http.HandleFunc("/rpnNameAndCard", rpnNameAndCard) //ask name and card no
- http.HandleFunc("/rpn_notify", rpnNotify) //called by rpn
- http.HandleFunc("/alipay", leanworkInFAT) // leanwork in
- fs := wrapHandler(http.FileServer(http.Dir("./PG"))) //leanwork P2P embeded in
- http.HandleFunc("/", fs)
-
- //start listening
- svr := Config.Server.Host + ":" + Config.Server.Port
- log.Println("Server started on: " + svr)
- http.ListenAndServe(svr, nil)
-
- //program never reach here.
- }
-
- func errPage(w http.ResponseWriter, code int, msg string) {
- var data struct {
- ErrorMessage string
- }
- data.ErrorMessage = msg
- w.WriteHeader(code)
- t := template.Must(template.ParseFiles("PG/error.html"))
- t.Execute(w, data)
- }
|