Example #1
0
// link worker code.
func linkCode() bool {
	configFile := os.Getenv("GOPATH") + "/src/git.masontest.com/branches/goserver/config.yml" // 默认配置文件在当前运行命令目录下的config.yml
	env := "dev"

	// 获取配置信息.
	mainConfig, serviceConfig := config.GetConfig(configFile, env)

	// log
	log := plugins.NewServerLog("")

	appNames := []string{}
	for sn, config := range serviceConfig {
		if config["handle_path"] != "" {
			appNames = append(appNames, sn)
		}
	}

	r.BuildAppLink(appNames)

	if len(appNames) == 0 {
		return false
	}

	for sn, config := range serviceConfig {
		// to link apps code to runtime
		r.Build(mainConfig["env"], sn, config["handle_path"], log)
	}

	return true
}
Example #2
0
func NewGoServer(mainConfig map[string]string, serviceConfig map[string]map[string]string) *GoServer {
	return &GoServer{
		MainCfg:   mainConfig,
		ServerCfg: serviceConfig,
		Log:       plugins.NewServerLog(""),
		Ch:        make(chan os.Signal),
	}
}
Example #3
0
func Test_Build(t *testing.T) {
	logger := plugins.NewServerLog("test")

	_, serviceConfig := config.GetConfig("../../config.yml", "dev")

	for appName, config := range serviceConfig {
		r.Build(appName, config["handle_path"], logger)
	}
}
Example #4
0
func NewRpcWorker(id int, secretKey string, config *map[string]string, listener interface{}, sync chan int) *RpcWorker {
	var worker *RpcWorker

	logger := plugins.NewServerLog((*config)["name"])
	duration, _ := time.ParseDuration((*config)["process_timeout"] + "ms")

	if tcpListener, ok := listener.(*net.TCPListener); ok {
		worker = &RpcWorker{
			Id:          id,
			Log:         logger,
			Config:      config,
			TcpListener: tcpListener,
			UdpConn:     nil,
			SecretKey:   secretKey,
			Proto:       protocols.NewTextProtocol(logger),
			Duration:    duration,
			IsTcp:       true,
			Sync:        sync,
		}
	} else if udpConn, ok := listener.(*net.UDPConn); ok {

		worker = &RpcWorker{
			Id:          id,
			Log:         logger,
			Config:      config,
			TcpListener: nil,
			UdpConn:     udpConn,
			SecretKey:   secretKey,
			Proto:       protocols.NewTextProtocol(logger),
			Duration:    duration,
			IsTcp:       false,
			Sync:        sync,
		}
	}

	// currect the worker id by channel
	worker.Id, _ = <-worker.Sync
	return worker
}
Example #5
0
func init() {
	logger = plugins.NewServerLog("tony")
}