<commit_before>package dou

import (
	"fmt"
	"log"
	"net"
	"net/http"
	"runtime"
	"strings"
	"time"
)

var (
	plugins = map[string]Plugin{}
)

// Config can store configuration map for Api.
type Config map[string]interface{}

// Plugin is interface for dou.Api plugin.
// This plugin system make dou flexible and thin.
// You can create Plugin like a github.com/ToQoz/dou/jsonapi in accordance the use.
// see also github.com/ToQoz/dou/jsonapi
type Plugin interface {
	OnPanic(w http.ResponseWriter, r *http.Request)
	BeforeDispatch(w http.ResponseWriter, r *http.Request) (http.ResponseWriter, *http.Request)
	AfterDispatch(w http.ResponseWriter, r *http.Request) (http.ResponseWriter, *http.Request)
	Marshal(v interface{}) ([]byte, error)
	Unmarshal(data []byte, v interface{}) error
	APIStatus(w http.ResponseWriter, code int)
}

// SafeWriter is safe http.ResponseWriter
// For prevent unintentionally multiple calling http.ResponseWriter.Write, this has bool `Worte`.
// When recovering panic, this is useful for prevent unintentionally writing to the continuation that was written before panic.
// Example: Write([]byte(`[]`)) ->
//          SomeFunc() -> (panic) -> OnPanic() ->
//          Write(`{"message": "Internal server error"}`)
// In ideal theory that I think, we have to prevent panic after calling Write. But no accident, no life :)
type SafeWriter struct {
	Wrote bool
	http.ResponseWriter
}

func NewSafeWriter(w http.ResponseWriter) *SafeWriter {
	return &SafeWriter{false, w}
}

func (sw *SafeWriter) Write(p []byte) (int, error) {
	sw.Wrote = true
	return sw.ResponseWriter.Write(p)<commit_msg>Add doc to dou.NewSafeWriter. Follow golint.<commit_after>package dou

import (
	"fmt"
	"log"
	"net"
	"net/http"
	"runtime"
	"strings"
	"time"
)

var (
	plugins = map[string]Plugin{}
)

// Config can store configuration map for Api.
type Config map[string]interface{}

// Plugin is interface for dou.Api plugin.
// This plugin system make dou flexible and thin.
// You can create Plugin like a github.com/ToQoz/dou/jsonapi in accordance the use.
// see also github.com/ToQoz/dou/jsonapi
type Plugin interface {
	OnPanic(w http.ResponseWriter, r *http.Request)
	BeforeDispatch(w http.ResponseWriter, r *http.Request) (http.ResponseWriter, *http.Request)
	AfterDispatch(w http.ResponseWriter, r *http.Request) (http.ResponseWriter, *http.Request)
	Marshal(v interface{}) ([]byte, error)
	Unmarshal(data []byte, v interface{}) error
	APIStatus(w http.ResponseWriter, code int)
}

// SafeWriter is safe http.ResponseWriter
// For prevent unintentionally multiple calling http.ResponseWriter.Write, this has bool `Worte`.
// When recovering panic, this is useful for prevent unintentionally writing to the continuation that was written before panic.
// Example: Write([]byte(`[]`)) ->
//          SomeFunc() -> (panic) -> OnPanic() ->
//          Write(`{"message": "Internal server error"}`)
// In ideal theory that I think, we have to prevent panic after calling Write. But no accident, no life :)
type SafeWriter struct {
	Wrote bool
	http.ResponseWriter
}

// NewSafeWriter new SafeWriter by given http.ResponseWriter
func NewSafeWriter(w http.ResponseWriter) *SafeWriter {
	return &SafeWriter{false, w}
}

func (sw *SafeWriter) Write(p []byte) (int, error) {
	sw.Wrote = true
	return sw.ResponseWriter.Write(p)
{'fraction_non_alphanumeric': 0.1219951923076923, 'fraction_numerical': 0.0, 'mean_word_length': 4.309409888357257, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 11, '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': '1096638', 'n_tokens_mistral': 1028, 'n_tokens_neox': 1002, 'n_words': 344}