<commit_before>package ak

import (
	"encoding/json"
	"log"
	"net/http"
	"path"
	"reflect"
	"strconv"
)

//定义方法类型
type actionFunc func(*Context)

//请求上下文
type Context struct {
	Request        *http.Request
	ResponseWriter http.ResponseWriter
	Params         map[string]string
	Data           map[string]interface{} //返回参数定义
	server         *Server
	Session        *Session
	closed         bool
}

//返回json
func (ctx *Context) WriteJson(content interface{}) {
	if ctx.closed {
		return
	}
	ctx.ResponseWriter.Header().Set("Content-Type", "application/json;charset=UTF-8")
	cv := reflect.ValueOf(content)
	log.Println("cv = ", cv.Type().Kind())
	if cv.Type().Kind() == reflect.String {
		ctx.ResponseWriter.Write([]byte(cv.String()))
	} else if cv.Type().Kind() == reflect.Struct || cv.Type().Kind() == reflect.Slice || cv.Type().Kind() == reflect.Ptr || cv.Type().Kind() == reflect.Map {
		jsonData, err := json.Marshal(content)<commit_msg>fix type().Kind()<commit_after>package ak

import (
	"encoding/json"
	"net/http"
	"path"
	"reflect"
	"strconv"
)

//定义方法类型
type actionFunc func(*Context)

//请求上下文
type Context struct {
	Request        *http.Request
	ResponseWriter http.ResponseWriter
	Params         map[string]string
	Data           map[string]interface{} //返回参数定义
	server         *Server
	Session        *Session
	closed         bool
}

//返回json
func (ctx *Context) WriteJson(content interface{}) {
	if ctx.closed {
		return
	}
	ctx.ResponseWriter.Header().Set("Content-Type", "application/json;charset=UTF-8")
	cv := reflect.ValueOf(content)
	vkind := cv.Type().Kind()
	if vkind == reflect.String {
		ctx.ResponseWriter.Write([]byte(cv.String()))
	} else if vkind == reflect.Struct || vkind == reflect.Slice || vkind == reflect.Ptr || vkind == reflect.Map {
		jsonData, err := json.Marshal(content)
{'fraction_non_alphanumeric': 0.15938018815716656, 'fraction_numerical': 0.0011068068622025456, 'mean_word_length': 3.531328320802005, 'pattern_counts': {'":': 0, '<': 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': '3648819', 'n_tokens_mistral': 621, 'n_tokens_neox': 613, 'n_words': 127}