|
|
|
@@ -36,6 +36,8 @@ func setupApiV1Handler() []apiV1HandlerMap { |
|
|
|
{"GET", "chart/recent-10-loans", apiV1ChartRecent10Loans}, |
|
|
|
{"GET", "chart/top-broker", apiV1ChartTopBroker}, |
|
|
|
{"POST", "grid/loan/full-loan-overview", apiV1GridLoanFullOverview}, |
|
|
|
{"GET", "loan/", apiV1LoanSingleGet}, |
|
|
|
{"POST", "loan/basic/", apiV1LoanSinglePostBasic}, |
|
|
|
{"GET", "avatar/", apiV1Avatar}, |
|
|
|
{"GET", "login", apiV1DumpRequest}, |
|
|
|
} |
|
|
|
@@ -49,6 +51,8 @@ func setupApiV1Handler() []apiV1HandlerMap { |
|
|
|
{"GET", "chart/recent-10-loans", apiV1ChartRecent10Loans}, |
|
|
|
{"GET", "chart/top-broker", apiV1ChartTopBroker}, |
|
|
|
{"POST", "grid/loan/full-loan-overview", apiV1GridLoanFullOverview}, |
|
|
|
{"GET", "loan/", apiV1LoanSingleGet}, |
|
|
|
{"POST", "loan/basic/", apiV1LoanSinglePostBasic}, |
|
|
|
{"GET", "avatar/", apiV1Avatar}, |
|
|
|
{"GET", "login", apiV1EmptyResponse}, |
|
|
|
} |
|
|
|
@@ -181,6 +185,14 @@ func apiV1InitSessionByBrowserId(r *http.Request) (session loan.Session, e error |
|
|
|
} |
|
|
|
|
|
|
|
func apiV1AddTrackingCookie(w http.ResponseWriter, r *http.Request, session *loan.Session) { |
|
|
|
//set session header too. |
|
|
|
w.Header().Add("Access-Control-Expose-Headers", "Biukop-Session") |
|
|
|
if session == nil { |
|
|
|
w.Header().Add("Biukop-Session", "") |
|
|
|
} else { |
|
|
|
w.Header().Add("Biukop-Session", session.Id) |
|
|
|
} |
|
|
|
|
|
|
|
//add tracking cookie |
|
|
|
expiration := time.Now().Add(365 * 24 * time.Hour) |
|
|
|
mid := apiV1GetMachineId(r) |
|
|
|
@@ -208,6 +220,7 @@ func apiV1InitSessionByHttpHeader(r *http.Request) (ss loan.Session, e error) { |
|
|
|
e = errors.New("session not found: " + sid) |
|
|
|
} |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
func apiV1ErrorCheck(e error) { |
|
|
|
@@ -247,6 +260,25 @@ func apiV1Client403Error(w http.ResponseWriter, r *http.Request, ss *loan.Sessio |
|
|
|
log.Warnf("Not authorized http(%s) path= %s, %s", r.Method, r.URL.Path, dump) |
|
|
|
} |
|
|
|
|
|
|
|
func apiV1Client404Error(w http.ResponseWriter, r *http.Request, ss *loan.Session) { |
|
|
|
w.WriteHeader(404) |
|
|
|
type struct404 struct { |
|
|
|
Error int |
|
|
|
ErrorMsg string |
|
|
|
} |
|
|
|
e404 := struct404{Error: 404, ErrorMsg: "Not Found " + time.Now().Format(time.RFC1123)} |
|
|
|
msg404, _ := json.Marshal(e404) |
|
|
|
|
|
|
|
//before send out |
|
|
|
apiV1AddTrackingCookie(w, r, ss) //always the last one to set cookies |
|
|
|
fmt.Fprintln(w, string(msg404)) |
|
|
|
|
|
|
|
//write log |
|
|
|
dump := logRequestDebug(httputil.DumpRequest(r, true)) |
|
|
|
dump = strings.TrimSpace(dump) |
|
|
|
log.Warnf("Not found http(%s) path= %s, %s", r.Method, r.URL.Path, dump) |
|
|
|
} |
|
|
|
|
|
|
|
func apiV1DumpRequest(w http.ResponseWriter, r *http.Request, ss *loan.Session) { |
|
|
|
dump := logRequestDebug(httputil.DumpRequest(r, true)) |
|
|
|
dump = strings.TrimSpace(dump) |