payment gateway for rpn cn
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

62 行
1.4KB

  1. package main
  2. import (
  3. "log"
  4. "net/http"
  5. "os"
  6. "path/filepath"
  7. "text/template"
  8. "time"
  9. )
  10. func main() {
  11. db.h = nil //make sure it's in proper state.
  12. workingdir := getWorkingDir()
  13. //setup log file
  14. filename := workingdir + "/logs/rpn.superforex." + time.Now().Format("2006-01-02-15-04-06") + ".log"
  15. f, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
  16. if err != nil {
  17. log.Fatalf("Error opening file: %v", err)
  18. }
  19. defer f.Close()
  20. log.SetOutput(f)
  21. //Read Config
  22. readConfig()
  23. //readConfigForTest()
  24. //setup http handler
  25. http.HandleFunc("/rpnNameAndCard", rpnNameAndCard) //ask name and card no
  26. http.HandleFunc("/rpn_notify", rpnNotify) //called by rpn
  27. http.HandleFunc("/alipay", leanworkInFAT) // leanwork in
  28. fs := wrapHandler(http.FileServer(http.Dir("./PG"))) //leanwork P2P embeded in
  29. http.HandleFunc("/", fs)
  30. //start listening
  31. svr := Config.Server.Host + ":" + Config.Server.Port
  32. log.Println("Server started on: " + svr)
  33. http.ListenAndServe(svr, nil)
  34. //program never reach here.
  35. }
  36. func getWorkingDir() string {
  37. dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
  38. if err != nil {
  39. log.Fatal(err)
  40. }
  41. return dir
  42. }
  43. func errPage(w http.ResponseWriter, code int, msg string) {
  44. var data struct {
  45. ErrorMessage string
  46. }
  47. data.ErrorMessage = msg
  48. w.WriteHeader(code)
  49. t := template.Must(template.ParseFiles("PG/error.html"))
  50. t.Execute(w, data)
  51. }