Sfoglia il codice sorgente

add got init and enable log timing.

master
sp 4 anni fa
parent
commit
d860183eec
1 ha cambiato i file con 14 aggiunte e 20 eliminazioni
  1. +14
    -20
      main.go

+ 14
- 20
main.go Vedi File

@@ -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)
}

Loading…
Annulla
Salva