| package main | package main | ||||
| import ( | import ( | ||||
| "biukop/sfm/loan" | |||||
| "biukop.com/sfm/loan" | |||||
| "encoding/gob" | |||||
| "encoding/json" | "encoding/json" | ||||
| "fmt" | "fmt" | ||||
| log "github.com/sirupsen/logrus" | log "github.com/sirupsen/logrus" | ||||
| "net/http" | "net/http" | ||||
| "net/http/httputil" | |||||
| "strings" | |||||
| ) | ) | ||||
| type httpEntry func(http.ResponseWriter, *http.Request) | type httpEntry func(http.ResponseWriter, *http.Request) | ||||
| } | } | ||||
| func init() { | |||||
| gob.Register(loginForm{}) | |||||
| customFormatter := new(log.TextFormatter) | |||||
| customFormatter.TimestampFormat = "2006-01-02 15:04:05" | |||||
| log.SetFormatter(customFormatter) | |||||
| log.Info("Change Log Format before FullTimestamp=true") | |||||
| customFormatter.FullTimestamp = true | |||||
| } | |||||
| func setupRootFileServer() { | func setupRootFileServer() { | ||||
| //root of doc | //root of doc | ||||
| for idx, node := range config.Static { | for idx, node := range config.Static { | ||||
| } | } | ||||
| log.Printf("Server started at %s:%s\n", config.Host, config.Port) | log.Printf("Server started at %s:%s\n", config.Host, config.Port) | ||||
| log.Fatal(http.ListenAndServe(config.Host+":"+config.Port, nil)) | |||||
| //log.Fatal(http.ListenAndServe(config.Host+":"+config.Port, nil)) | |||||
| log.Fatal(http.ListenAndServeTLS(config.Host+":"+config.Port, config.TlsCert, config.TlsKey, nil)) | |||||
| } | } | ||||
| apiV1DumpRequest(w, nil, nil) | apiV1DumpRequest(w, nil, nil) | ||||
| } | } | ||||
| } | } | ||||
| func apiV1DumpRequest(w http.ResponseWriter, r *http.Request, ss *loan.Session) { | |||||
| dump := logRequestDebug(httputil.DumpRequest(r, true)) | |||||
| dump = strings.TrimSpace(dump) | |||||
| msg := fmt.Sprintf("Unhandled Protocol = %s path= %s", r.Method, r.URL.Path) | |||||
| dumpLines := strings.Split(dump, "\r\n") | |||||
| ar := apiV1ResponseBlank() | |||||
| ar.Env.Msg = msg | |||||
| ar.Env.Session = *ss | |||||
| ar.Env.Session.Bin = []byte("masked data") //clear | |||||
| ar.Env.Session.Secret = "***********" | |||||
| ar.add("Body", dumpLines) | |||||
| ar.add("mid", ss.Get("mid")) | |||||
| b, _ := ar.toJson() | |||||
| fmt.Fprintf(w, "%s\n", b) | |||||
| } |