<commit_before>// Code generated by protoc-gen-gohttp. DO NOT EDIT.
// source: httprule/all_pattern.proto

package httprulepb

import (
	"bytes"
	"context"
	"encoding/json"
	"fmt"
	"io"
	"io/ioutil"
	"net/http"
	"strings"

	"github.com/golang/protobuf/jsonpb"
	"github.com/golang/protobuf/proto"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"
)

// AllPatternHTTPConverter has a function to convert AllPatternServer interface to http.HandlerFunc.
type AllPatternHTTPConverter struct {
	srv AllPatternServer
}

// NewAllPatternHTTPConverter returns AllPatternHTTPConverter.
func NewAllPatternHTTPConverter(srv AllPatternServer) *AllPatternHTTPConverter {
	return &AllPatternHTTPConverter{
		srv: srv,
	}
}

// AllPattern returns AllPatternServer interface's AllPattern converted to http.HandlerFunc.
func (h *AllPatternHTTPConverter) AllPattern(cb func(ctx context.Context, w http.ResponseWriter, r *http.Request, arg, ret proto.Message, err error)) http.HandlerFunc {
	if cb == nil {
		cb = func(ctx context.Context, w http.ResponseWriter, r *http.Request, arg, ret proto.Message, err error) {
			if err != nil {
				w.WriteHeader(http.StatusInternalServerError)
				p := status.New(codes.Unknown, err.Error()).Proto()
				switch r.Header.Get("Content-Type") {
				case "application/protobuf", "application/x-protobuf":
					buf, err := proto.Marshal(p)
					if err != nil {
						return
					}
					if _, err := io.Copy(w, bytes.NewBuffer(buf)); err != nil {
						return
					}
				case "application/json":
					if err := json.NewEncoder(w).Encode(p); err != nil {
						return
					}
				default:
				}
			}
		}
	}
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		ctx := r.Context()

		arg := &AllPatternRequest{}
		contentType := r.Header.Get("Content-Type")
		if r.Method != http.MethodGet {
			body, err := ioutil.ReadAll(r.Body)
			if err != nil {
				cb(ctx, w, r, nil, nil, err)
				return
			}

			switch contentType {
			case "application/protobuf", "application/x-protobuf":
				if err := proto.Unmarshal(body, arg); err != nil {
					cb(ctx, w, r, nil, nil, err)
					return
				}
			case "application/json":
				if err := jsonpb.Unmarshal(bytes.NewBuffer(body), arg); err != nil {
					cb(ctx, w, r, nil, nil, err)
					return
				}
			default:
				w.WriteHeader(http.StatusUnsupportedMediaType)
				_, err := fmt.Fprintf(w, "Unsupported Content-Type: %s", contentType)
				cb(ctx, w, r, nil, nil, err)
				return
			}
		}

		ret, err := h.srv.AllPattern(ctx, arg)
		if err != nil {
			cb(ctx, w, r, arg, nil, err)
			return
		}

		accepts := strings.Split(r.Header.Get("Accept"), ",")
		accept := accepts[0]
		if accept == "*/*" || accept == "" {
			if contentType != "" {
				accept = contentType
			} else {
				accept = "application/json"
			}
		}

		switch accept {
		case "application/protobuf", "application/x-protobuf":
			buf, err := proto.Marshal(ret)
			if err != nil {
				cb(ctx, w, r, arg, ret, err)
				return
			}
			if _, err := io.Copy(w, bytes.NewBuffer(buf)); err != nil {
				cb(ctx, w, r, arg, ret, err)
				return
			}
		case "application/json":
			m := jsonpb.Marshaler{
				EnumsAsInts:  true,
				EmitDefaults: true,
			}
			if err := m.Marshal(w, ret); err != nil {
				cb(ctx, w, r, arg, ret, err)
				return
			}
		default:
			w.WriteHeader(http.StatusUnsupportedMediaType)
			_, err := fmt.Fprintf(w, "Unsupported Accept: %s", accept)
			cb(ctx, w, r, arg, ret, err)
			return
		}
		cb(ctx, w, r, arg, ret, nil)
	})
}

// AllPatternWithName returns Service name, Method name and AllPatternServer interface's AllPattern converted to http.HandlerFunc.
func (h *AllPatternHTTPConverter) AllPatternWithName(cb func(ctx context.Context, w http.ResponseWriter, r *http.Request, arg, ret proto.Message, err error)) (string, string, http.HandlerFunc) {
	return "AllPattern", "AllPattern", h.AllPattern(cb)
}

func (h *AllPatternHTTPConverter) AllPatternHTTPRule(cb func(ctx context.Context, w http.ResponseWriter, r *http.Request, arg, ret proto.Message, err error)) (string, string, http.HandlerFunc) {
	if cb == nil {
		cb = func(ctx context.Context, w http.ResponseWriter, r *http.Request, arg, ret proto.Message, err error) {
			if err != nil {
				w.WriteHeader(http.StatusInternalServerError)
				p := status.New(codes.Unknown, err.Error()).Proto()
				switch r.Header.Get("Content-Type") {
				case "application/protobuf", "application/x-protobuf":
					buf, err := proto.Marshal(p)
					if err != nil {
						return
					}
					if _, err := io.Copy(w, bytes.NewBuffer(buf)); err != nil {
						return
					}
				case "application/json":
					if err := json.NewEncoder(w).Encode(p); err != nil {
						return
					}
				default:
				}
			}
		}
	}
	return http.MethodGet, "/all/pattern", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		ctx := r.Context()

		arg := &AllPatternRequest{}
		contentType := r.Header.Get("Content-Type")
		if r.Method == http.MethodGet {
			var err error
			arg.String_ = r.URL.Query().Get("string")
		}

		ret, err := h.srv.AllPattern(ctx, arg)
		if err != nil {
			cb(ctx, w, r, arg, nil, err)
			return
		}<commit_msg>Added single var type test case<commit_after>// Code generated by protoc-gen-gohttp. DO NOT EDIT.
// source: httprule/all_pattern.proto

package httprulepb

import (
	"bytes"
	"context"
	"encoding/base64"
	"encoding/json"
	"fmt"
	"io"
	"io/ioutil"
	"net/http"
	"strconv"
	"strings"

	"github.com/golang/protobuf/jsonpb"
	"github.com/golang/protobuf/proto"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"
)

// AllPatternHTTPConverter has a function to convert AllPatternServer interface to http.HandlerFunc.
type AllPatternHTTPConverter struct {
	srv AllPatternServer
}

// NewAllPatternHTTPConverter returns AllPatternHTTPConverter.
func NewAllPatternHTTPConverter(srv AllPatternServer) *AllPatternHTTPConverter {
	return &AllPatternHTTPConverter{
		srv: srv,
	}
}

// AllPattern returns AllPatternServer interface's AllPattern converted to http.HandlerFunc.
func (h *AllPatternHTTPConverter) AllPattern(cb func(ctx context.Context, w http.ResponseWriter, r *http.Request, arg, ret proto.Message, err error)) http.HandlerFunc {
	if cb == nil {
		cb = func(ctx context.Context, w http.ResponseWriter, r *http.Request, arg, ret proto.Message, err error) {
			if err != nil {
				w.WriteHeader(http.StatusInternalServerError)
				p := status.New(codes.Unknown, err.Error()).Proto()
				switch r.Header.Get("Content-Type") {
				case "application/protobuf", "application/x-protobuf":
					buf, err := proto.Marshal(p)
					if err != nil {
						return
					}
					if _, err := io.Copy(w, bytes.NewBuffer(buf)); err != nil {
						return
					}
				case "application/json":
					if err := json.NewEncoder(w).Encode(p); err != nil {
						return
					}
				default:
				}
			}
		}
	}
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		ctx := r.Context()

		arg := &AllPatternRequest{}
		contentType := r.Header.Get("Content-Type")
		if r.Method != http.MethodGet {
			body, err := ioutil.ReadAll(r.Body)
			if err != nil {
				cb(ctx, w, r, nil, nil, err)
				return
			}

			switch contentType {
			case "application/protobuf", "application/x-protobuf":
				if err := proto.Unmarshal(body, arg); err != nil {
					cb(ctx, w, r, nil, nil, err)
					return
				}
			case "application/json":
				if err := jsonpb.Unmarshal(bytes.NewBuffer(body), arg); err != nil {
					cb(ctx, w, r, nil, nil, err)
					return
				}
			default:
				w.WriteHeader(http.StatusUnsupportedMediaType)
				_, err := fmt.Fprintf(w, "Unsupported Content-Type: %s", contentType)
				cb(ctx, w, r, nil, nil, err)
				return
			}
		}

		ret, err := h.srv.AllPattern(ctx, arg)
		if err != nil {
			cb(ctx, w, r, arg, nil, err)
			return
		}

		accepts := strings.Split(r.Header.Get("Accept"), ",")
		accept := accepts[0]
		if accept == "*/*" || accept == "" {
			if contentType != "" {
				accept = contentType
			} else {
				accept = "application/json"
			}
		}

		switch accept {
		case "application/protobuf", "application/x-protobuf":
			buf, err := proto.Marshal(ret)
			if err != nil {
				cb(ctx, w, r, arg, ret, err)
				return
			}
			if _, err := io.Copy(w, bytes.NewBuffer(buf)); err != nil {
				cb(ctx, w, r, arg, ret, err)
				return
			}
		case "application/json":
			m := jsonpb.Marshaler{
				EnumsAsInts:  true,
				EmitDefaults: true,
			}
			if err := m.Marshal(w, ret); err != nil {
				cb(ctx, w, r, arg, ret, err)
				return
			}
		default:
			w.WriteHeader(http.StatusUnsupportedMediaType)
			_, err := fmt.Fprintf(w, "Unsupported Accept: %s", accept)
			cb(ctx, w, r, arg, ret, err)
			return
		}
		cb(ctx, w, r, arg, ret, nil)
	})
}

// AllPatternWithName returns Service name, Method name and AllPatternServer interface's AllPattern converted to http.HandlerFunc.
func (h *AllPatternHTTPConverter) AllPatternWithName(cb func(ctx context.Context, w http.ResponseWriter, r *http.Request, arg, ret proto.Message, err error)) (string, string, http.HandlerFunc) {
	return "AllPattern", "AllPattern", h.AllPattern(cb)
}

func (h *AllPatternHTTPConverter) AllPatternHTTPRule(cb func(ctx context.Context, w http.ResponseWriter, r *http.Request, arg, ret proto.Message, err error)) (string, string, http.HandlerFunc) {
	if cb == nil {
		cb = func(ctx context.Context, w http.ResponseWriter, r *http.Request, arg, ret proto.Message, err error) {
			if err != nil {
				w.WriteHeader(http.StatusInternalServerError)
				p := status.New(codes.Unknown, err.Error()).Proto()
				switch r.Header.Get("Content-Type") {
				case "application/protobuf", "application/x-protobuf":
					buf, err := proto.Marshal(p)
					if err != nil {
						return
					}
					if _, err := io.Copy(w, bytes.NewBuffer(buf)); err != nil {
						return
					}
				case "application/json":
					if err := json.NewEncoder(w).Encode(p); err != nil {
						return
					}
				default:
				}
			}
		}
	}
	return http.MethodGet, "/all/pattern", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		ctx := r.Context()

		arg := &AllPatternRequest{}
		contentType := r.Header.Get("Content-Type")
		if r.Method == http.MethodGet {
			{
				d, err := strconv.ParseFloat(r.URL.Query().Get("double"), 64)
				if err != nil {
					cb(ctx, w, r, nil, nil, err)
					return
				}
				arg.Double = d
			}
			{
				f, err := strconv.ParseFloat(r.URL.Query().Get("float"), 32)
				if err != nil {
					cb(ctx, w, r, nil, nil, err)
					return
				}
				arg.Float = float32(f)
			}
			{
				i32, err := strconv.ParseInt(r.URL.Query().Get("int32"), 10, 32)
				if err != nil {
					cb(ctx, w, r, nil, nil, err)
					return
				}
				arg.Int32 = int32(i32)
			}
			{
				i64, err := strconv.ParseInt(r.URL.Query().Get("int64"), 10, 64)
				if err != nil {
					cb(ctx, w, r, nil, nil, err)
					return
				}
				arg.Int64 = i64
			}
			{
				ui32, err := strconv.ParseUint(r.URL.Query().Get("uint32"), 10, 32)
				if err != nil {
					cb(ctx, w, r, nil, nil, err)
					return
				}
				arg.Uint32 = uint32(ui32)
			}
			{
				ui64, err := strconv.ParseUint(r.URL.Query().Get("uint64"), 10, 64)
				if err != nil {
					cb(ctx, w, r, nil, nil, err)
					return
				}
				arg.Uint64 = uint64(ui64)
			}
			{
				f32, err := strconv.ParseUint(r.URL.Query().Get("fixed32"), 10, 32)
				if err != nil {
					cb(ctx, w, r, nil, nil, err)
					return
				}
				arg.Fixed32 = uint32(f32)
			}
			{
				f64, err := strconv.ParseUint(r.URL.Query().Get("fixed64"), 10, 64)
				if err != nil {
					cb(ctx, w, r, nil, nil, err)
					return
				}
				arg.Fixed64 = uint64(f64)
			}
			{
				sf32, err := strconv.ParseInt(r.URL.Query().Get("sfixed32"), 10, 32)
				if err != nil {
					cb(ctx, w, r, nil, nil, err)
					return
				}
				arg.Sfixed32 = int32(sf32)
			}
			{
				sf64, err := strconv.ParseInt(r.URL.Query().Get("sfixed64"), 10, 64)
				if err != nil {
					cb(ctx, w, r, nil, nil, err)
					return
				}
				arg.Sfixed64 = int64(sf64)
			}
			{
				b, err := strconv.ParseBool(r.URL.Query().Get("bool"))
				if err != nil {
					cb(ctx, w, r, nil, nil, err)
					return
				}
				arg.Bool = b
			}
			arg.String_ = r.URL.Query().Get("string")
			{
				b, err := strconv.ParseBool(r.URL.Query().Get("bool"))
				if err != nil {
					cb(ctx, w, r, nil, nil, err)
					return
				}
				arg.Bool = b
			}
			{
				b, err := base64.StdEncoding.DecodeString(r.URL.Query().Get("bytes"))
				if err != nil {
					cb(ctx, w, r, nil, nil, err)
					return
				}
				arg.Bytes = b
			}
		}

		ret, err := h.srv.AllPattern(ctx, arg)
		if err != nil {
			cb(ctx, w, r, arg, nil, err)
			return
		}
{'fraction_non_alphanumeric': 0.1527370672581795, 'fraction_numerical': 0.009664897409490612, 'mean_word_length': 2.931485518530053, 'pattern_counts': {'":': 16, '<': 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': '5815721', 'n_tokens_mistral': 5458, 'n_tokens_neox': 4434, 'n_words': 1095}