<commit_before>package main

import (
	"github.com/dingdayu/gochatting/handlers"
	"net/http"
	"log"
	"runtime/debug"
)

func main() {
	// 注册一个路由
	http.HandleFunc("/hello", safeWebHandler(handlers.Hello))
	http.HandleFunc("/api/json", handlers.HelloJson)
	http.HandleFunc("/public/", handlers.PublicHandler)

	// 监听端口 8080
	err := http.ListenAndServe(":8080", nil)
	if err != nil {
		panic(err)
	}
}

// 服务器内部错误拦截
func safeWebHandler(fn http.HandlerFunc) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		// 遇到错误时的扫尾工作
		defer func() {
			// 终止（拦截）错误的传递
			if e, ok := recover().(error); ok {
				http.Error(w, e.Error(), http.StatusInternalServerError)
				// 或者输出自定义的50x错误页面
				//w.WriteHeader(http.StatusInternalServerError)
				//handlers.LoadHtml(w, "./templates/50x.html", nil)
				log.Println("WARN: panic in %v. - %v", fn, e)
				log.Println(string(debug.Stack()))
			}
		}()
		// 调用传入的方法名
		fn(w, r)
	}
}<commit_msg>* 修复文件名命名错误<commit_after>package main

import (
	"github.com/dingdayu/gochatting/handlers"
	"net/http"
	"log"
	"runtime/debug"
)

func main() {
	// 注册一个路由
	http.HandleFunc("/hello", safeWebHandler(handlers.Hello))
	http.HandleFunc("/websocket", safeWebHandler(handlers.Connection))
	http.HandleFunc("/api/json", handlers.HelloJson)
	http.HandleFunc("/public/", handlers.PublicHandler)


	// 监听端口 8080
	err := http.ListenAndServe(":8080", nil)
	if err != nil {
		panic(err)
	}
}

// 服务器内部错误拦截
func safeWebHandler(fn http.HandlerFunc) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		// 遇到错误时的扫尾工作
		defer func() {
			// 终止（拦截）错误的传递
			if e, ok := recover().(error); ok {
				http.Error(w, e.Error(), http.StatusInternalServerError)
				// 或者输出自定义的50x错误页面
				//w.WriteHeader(http.StatusInternalServerError)
				//handlers.LoadHtml(w, "./templates/50x.html", nil)
				log.Println("WARN: panic in %v. - %v", fn, e)
				log.Println(string(debug.Stack()))
			}
		}()
		// 调用传入的方法名
		fn(w, r)
	}
}
{'fraction_non_alphanumeric': 0.17216861350939563, 'fraction_numerical': 0.01218892839004571, 'mean_word_length': 3.679334916864608, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1381272', 'n_tokens_mistral': 910, 'n_tokens_neox': 882, 'n_words': 129}