Пример #1
0
func (ela *Elaeagnus) servHTTP(port int) {
	log.Pinkf("[ela] Listen Port %d\n", port)
	err := http.ListenAndServe(fmt.Sprintf(":%d", port), ela)
	if err != nil {
		fmt.Printf("HTTP Server Start Failed Port [%d]\n%s", port, err)
	}
}
Пример #2
0
func responseLog(ctx Context) {
	content := "[%s] %s: complete %s %s %d\n"
	switch ctx.GetResponseWriter().Status() {
	case 301, 302:
		log.Bluef(content, tag, time.Now().Format(logTimeFormat), ctx.GetRequest().Method, ctx.GetRequest().RequestURI, ctx.GetResponseWriter().Status())
	case 304:
		log.Greenf(content, tag, time.Now().Format(logTimeFormat), ctx.GetRequest().Method, ctx.GetRequest().RequestURI, ctx.GetResponseWriter().Status())
	case 401, 403:
		log.Yellowf(content, tag, time.Now().Format(logTimeFormat), ctx.GetRequest().Method, ctx.GetRequest().RequestURI, ctx.GetResponseWriter().Status())
	case 404:
		log.Redf(content, tag, time.Now().Format(logTimeFormat), ctx.GetRequest().Method, ctx.GetRequest().RequestURI, ctx.GetResponseWriter().Status())
	case 500:
		log.Pinkf(content, tag, time.Now().Format(logTimeFormat), ctx.GetRequest().Method, ctx.GetRequest().RequestURI, ctx.GetResponseWriter().Status())
	default:
		log.Printf(content, tag, time.Now().Format(logTimeFormat), ctx.GetRequest().Method, ctx.GetRequest().RequestURI, ctx.GetResponseWriter().Status())
	}

}