Przeglądaj źródła

add logfile support

master
patrick 5 lat temu
rodzic
commit
57cfa58833
1 zmienionych plików z 15 dodań i 8 usunięć
  1. +15
    -8
      main.go

+ 15
- 8
main.go Wyświetl plik

import ( import (
"log" "log"
"net/http" "net/http"
"os"
"text/template" "text/template"
"time"
) )


func main() { func main() {
readConfigForTest() readConfigForTest()
db.h = nil //make sure it's in proper state. db.h = nil //make sure it's in proper state.


filename := "rpn.superforex." + time.Now().Format("20060102150406") + ".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)
log.Println("Server started on: http://localhost:8080")

//setup http handler
http.HandleFunc("/choosePayment", choosePayment) http.HandleFunc("/choosePayment", choosePayment)
http.HandleFunc("/rpnNameAndCard", rpnNameAndCard) http.HandleFunc("/rpnNameAndCard", rpnNameAndCard)
http.HandleFunc("/rpn_notify", rpnNotify) //called by rpn http.HandleFunc("/rpn_notify", rpnNotify) //called by rpn
// http.HandleFunc("/", Index)
// http.HandleFunc("/show", Show)
// http.HandleFunc("/new", New)
// http.HandleFunc("/edit", Edit)
// http.HandleFunc("/insert", Insert)
// http.HandleFunc("/update", Update)
// http.HandleFunc("/delete", Delete)
fs := wrapHandler(http.FileServer(http.Dir("./PG"))) fs := wrapHandler(http.FileServer(http.Dir("./PG")))
http.HandleFunc("/", fs) http.HandleFunc("/", fs)
http.ListenAndServe(":8080", nil) http.ListenAndServe(":8080", nil)
log.Println("Server started on: http://localhost:8080")

//start log file

} }


func errPage(w http.ResponseWriter, code int, msg string) { func errPage(w http.ResponseWriter, code int, msg string) {

Ładowanie…
Anuluj
Zapisz