<commit_before>package possum

import (
	"math/rand"
	"net/http"
)

// Method takes one map as a paramater.
// Keys of this map are HTTP method mapping to HandlerFunc(s).
func Method(m map[string]HandlerFunc) HandlerFunc {
	f := func(ctx *Context) error {
		h, ok := m[ctx.Request.Method]
		if ok {
			return h(ctx)
		}
		ctx.Response.Status = http.StatusMethodNotAllowed
		return nil
	}
	return f
}

// Chain combins a slide of HandlerFunc(s) in to one request.
func Chain(h ...HandlerFunc) HandlerFunc {
	f := func(ctx *Context) error {
		for _, v := range h {
			if err := v(ctx); err != nil {
				return err
			}
		}
		return nil
	}
	return f
}

// Rand picks one HandlerFunc(s) in the slide.
func Rand(h ...HandlerFunc) HandlerFunc {
	f := func(ctx *Context) error {
		if err := h[rand.Intn(len(h))](ctx); err != nil {
			return err
		}
		return nil
	}
	return f
}

// WrapHttpHandlerFunc wraps http.HandlerFunc in possum.HandlerFunc.
// See pprof.go.
func WrapHttpHandlerFunc(f http.HandlerFunc) HandlerFunc {
	newF := func(ctx *Context) error {
		f(ctx.Response, ctx.Request)
		return nil
	}
	return newF
}<commit_msg>add a helper function for websocket<commit_after>package possum

import (
	"math/rand"
	"net/http"

	"golang.org/x/net/websocket"
)

// Method takes one map as a paramater.
// Keys of this map are HTTP method mapping to HandlerFunc(s).
func Method(m map[string]HandlerFunc) HandlerFunc {
	f := func(ctx *Context) error {
		h, ok := m[ctx.Request.Method]
		if ok {
			return h(ctx)
		}
		ctx.Response.Status = http.StatusMethodNotAllowed
		return nil
	}
	return f
}

// Chain combins a slide of HandlerFunc(s) in to one request.
func Chain(h ...HandlerFunc) HandlerFunc {
	f := func(ctx *Context) error {
		for _, v := range h {
			if err := v(ctx); err != nil {
				return err
			}
		}
		return nil
	}
	return f
}

// Rand picks one HandlerFunc(s) in the slide.
func Rand(h ...HandlerFunc) HandlerFunc {
	f := func(ctx *Context) error {
		if err := h[rand.Intn(len(h))](ctx); err != nil {
			return err
		}
		return nil
	}
	return f
}

// WrapHttpHandlerFunc wraps http.HandlerFunc in possum.HandlerFunc.
// See pprof.go.
func WrapHttpHandlerFunc(f http.HandlerFunc) HandlerFunc {
	newF := func(ctx *Context) error {
		f(ctx.Response, ctx.Request)
		return nil
	}
	return newF
}

// WebSocketHandlerFunc convert websocket function to possum.HandlerFunc
func WebSocketHandlerFunc(f func(ws *websocket.Conn)) HandlerFunc {
	h := websocket.Handler(f)
	return WrapHttpHandlerFunc(h.ServeHTTP)
}
{'fraction_non_alphanumeric': 0.1220675944333996, 'fraction_numerical': 0.0, 'mean_word_length': 3.40630472854641, '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': '2512763', 'n_tokens_mistral': 950, 'n_tokens_neox': 878, 'n_words': 267}