<commit_before>// Copyright (C) 2017 Jennal(<EMAIL>). All rights reserved.
//
// Licensed under the MIT License (the "License"); you may not use this file except
// in compliance with the License. You may obtain a copy of the License at
//
// http://opensource.org/licenses/MIT
//
// Unless required by applicable law or agreed to in writing, software distributed
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.

//Package router resolve network package route and find the right method to call
package router

import (
	"fmt"
	"reflect"
	"strings"

	"github.com/jennal/goplay/handler"
	"github.com/jennal/goplay/log"
	"github.com/jennal/goplay/pkg"
	"github.com/jennal/goplay/session"
)

var (
	TYPE_IHANDLER = reflect.TypeOf((*handler.IHandler)(nil)).Elem()
	TYPE_SESSION  = reflect.TypeOf(session.NewSession(nil))
	TYPE_ERROR    = reflect.TypeOf((*pkg.ErrorMessage)(nil))
)

type Router struct {
	serverName string
	data       map[string]*Method
}

func NewRouter(serverName string) *Router {
	return &Router{
		serverName: serverName,
		data:       make(map[string]*Method),
	}
}

func (r *Router) Add(obj interface{}) {
	tp := reflect.TypeOf(obj)
	// fmt.Println(tp.NumMethod())
	for i := 0; i < tp.NumMethod(); i++ {
		method := tp.Method(i)
		if !isValidMethod(method) {
			// fmt.Println("1", isValidMethod(method), method)
			continue
		}

		path := r.getPath(tp, method)
		if _, ok := r.data[path]; ok {
			log.Errorf("Router.Add: error: path(%v) already exists!", path)
			continue
		}

		r.data[path] = NewMethod(obj, method)<commit_msg>add Routes for Router<commit_after>// Copyright (C) 2017 Jennal(<EMAIL>). All rights reserved.
//
// Licensed under the MIT License (the "License"); you may not use this file except
// in compliance with the License. You may obtain a copy of the License at
//
// http://opensource.org/licenses/MIT
//
// Unless required by applicable law or agreed to in writing, software distributed
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
// CONDITIONS OF ANY KIND, either express or implied. See the License for the
// specific language governing permissions and limitations under the License.

//Package router resolve network package route and find the right method to call
package router

import (
	"fmt"
	"reflect"
	"strings"

	"github.com/jennal/goplay/handler"
	"github.com/jennal/goplay/log"
	"github.com/jennal/goplay/pkg"
	"github.com/jennal/goplay/session"
)

var (
	TYPE_IHANDLER = reflect.TypeOf((*handler.IHandler)(nil)).Elem()
	TYPE_SESSION  = reflect.TypeOf(session.NewSession(nil))
	TYPE_ERROR    = reflect.TypeOf((*pkg.ErrorMessage)(nil))
)

type Router struct {
	serverName string
	data       map[string]*Method
}

func NewRouter(serverName string) *Router {
	return &Router{
		serverName: serverName,
		data:       make(map[string]*Method),
	}
}

func (r *Router) Routes() []string {
	list := []string{}

	for route := range r.data {
		list = append(list, route)
	}

	return list
}

func (r *Router) Add(obj interface{}) {
	tp := reflect.TypeOf(obj)
	// fmt.Println(tp.NumMethod())
	for i := 0; i < tp.NumMethod(); i++ {
		method := tp.Method(i)
		if !isValidMethod(method) {
			// fmt.Println("1", isValidMethod(method), method)
			continue
		}

		path := r.getPath(tp, method)
		if _, ok := r.data[path]; ok {
			log.Errorf("Router.Add: error: path(%v) already exists!", path)
			continue
		}

		r.data[path] = NewMethod(obj, method)
{'fraction_non_alphanumeric': 0.13281682346430548, 'fraction_numerical': 0.003320420586607637, 'mean_word_length': 3.891745602165088, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '7173303', 'n_tokens_mistral': 1223, 'n_tokens_neox': 1162, 'n_words': 358}