func (r *ReqHandler) getRequestFunctionName(protocolName string) (string, bool) {
	if r.WorkMode == TestMode {
		return "Worker.GetTestResponse", true
	}
	if protocolName != "list" {
		protocolName = "custom"
	}
	reqFucn, ok := pathToReques[protocolName]
	return reqFucn, ok
}
getRequestFunctionName return name of method which will handle RCP request.
Second return value is bool, which indicates if function name was found or not.
package goworld
import (
	"encoding/json"
	"fmt"
	"log"
	"net/http"
	"net/rpc"
	"net/url"
	"strings"
	"time"
)
var (
	pathToReques = map[string]string{
		"list":   "Worker.ListObjectsFields",
		"custom": "Worker.Custom",
	}
)
type workerChan chan *WorkerConnection
func StartServer(config *Config, mode WorkMode) {
	online, offline := initWorkersConnections(config.Workers)
	go handleOfflineWorkers(online, offline)
	startHTTPServer(config, online, offline, mode)
	defer func() {
		if err := recover(); err != nil {
			log.Panic("PANIC ", err)
		}
	}()
}
func startHTTPServer(config *Config, online workerChan, offline workerChan, mode WorkMode) {
	port := config.Server.Port
	log.Printf("HTTP server started on port: %v\n", port)
	server := &http.Server{
		Addr: portNo(port),
		Handler: &ReqHandler{Online: online,
			Offline:  offline,
			Config:   config,
			WorkMode: mode},
		ReadTimeout:    1 * time.Minute,
		WriteTimeout:   1 * time.Minute,
		MaxHeaderBytes: 1 << 20,
	}
	log.Printf("SERVWER ERROR!\n %s\n", server.ListenAndServe())
}
func initWorkersConnections(workersDef []*WorkerConf) (onlineWorkers workerChan, offlineWorkers workerChan) {
	workersNo := len(workersDef)
	onlineWorkers = make(workerChan, workersNo)
	offlineWorkers = make(workerChan, workersNo)
	for _, workerDef := range workersDef {
		conn, err := rpc.DialHTTP("tcp", fmt.Sprintf("%s:%d", workerDef.Host, workerDef.Port))
		if err != nil {
			offlineWorkers <- &WorkerConnection{Host: workerDef.Host,
				Port: workerDef.Port,
				Name: workerDef.Name}
			continue
		}
		onlineWorkers <- &WorkerConnection{Host: workerDef.Host,
			Port: workerDef.Port,
			Name: workerDef.Name,
			Conn: conn}
		log.Printf("Worker %s (%s:%d), CONNECTED \n", workerDef.Name, workerDef.Host, workerDef.Port)
	}
	return
}
func handleOfflineWorkers(online workerChan, offline workerChan) {
	for {
		<-time.After(1 * time.Second)
		for worker := range offline {
			conn, err := rpc.DialHTTP("tcp", fmt.Sprintf("%s:%d", worker.Host, worker.Port))
			if err != nil {
				offline <- worker
			} else {
				log.Printf("Worker %s (%s:%d), CONNECTED \n", worker.Name, worker.Host, worker.Port)
				worker.Conn = conn
				online <- worker
			}
		}
	}
}
type WorkerConnection struct {
	Name string
	Host string
	Port int
	Conn *rpc.Client
}
type ReqHandler struct {
	Online   workerChan
	Offline  workerChan
	Config   *Config
	WorkMode WorkMode
}
func (r *ReqHandler) getProtocolConf(protocolName string) *ProtocolConf {
	return r.Config.GetProtocolDef(protocolName)
}