diff --git a/main.go b/main.go index e173dfc..4209b80 100644 --- a/main.go +++ b/main.go @@ -1,13 +1,12 @@ package main import ( - "biukop/sfm/loan" + "biukop.com/sfm/loan" + "encoding/gob" "encoding/json" "fmt" log "github.com/sirupsen/logrus" "net/http" - "net/http/httputil" - "strings" ) type httpEntry func(http.ResponseWriter, *http.Request) @@ -32,6 +31,16 @@ func main() { } +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() { //root of doc for idx, node := range config.Static { @@ -48,7 +57,8 @@ func setupHTTPHandler() { } 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)) } @@ -67,19 +77,3 @@ func apiSendJson(p interface{}, w http.ResponseWriter) { 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) -}