Esempio n. 1
0
func init() {
	gslogger.NewFlags(gslogger.ERROR | gslogger.INFO)
	go gorpc.TCPListen(acceptpor, ":13512")

	http.HandleFunc("/api", api)

	go http.ListenAndServe(":13513", nil)
}
Esempio n. 2
0
File: main.go Progetto: gsrpc/gsrpc
func main() {
	gslogger.Console("$content", "2006-01-02 15:04:05.999999")
	gslogger.NewFlags(gslogger.ERROR | gslogger.WARN | gslogger.INFO)
	log := gslogger.Get("gsrpc")

	defer func() {
		if e := recover(); e != nil {
			log.E("%s", e)
		}

		gslogger.Join()
	}()

	flag.Parse()

	*output, _ = filepath.Abs(*output)

	log.I("Start gsRPC With Target Language(%s)", *lang)

	codegenF, ok := langs[*lang]

	if !ok {
		log.E("unknown gsrpc object language :%s", *lang)
		os.Exit(1)
	}

	codegen, err := codegenF(*output, []string{"github.com/gsrpc/gslang"})

	if err != nil {
		gserrors.Panicf(err, "create language(%s) codegen error", *lang)
	}

	compiler := gslang.NewCompiler("gsrpc", gslang.HandleError(func(err *gslang.Error) {
		gserrors.Panicf(err.Orignal, "parse %s error\n\t%s", err.Start, err.Text)
	}))

	for _, file := range flag.Args() {
		log.I("Compile gsLang File :%s", file)
		if err := compiler.Compile(file); err != nil {
			gserrors.Panicf(err, "compile %s error", file)
		}
	}

	log.I("Link ...")
	err = compiler.Link()

	if err != nil {
		gserrors.Panicf(err, "link error")
	}

	log.I("Output Directory :%s", *output)

	if err := compiler.Visit(codegen); err != nil {
		gserrors.Panicf(err, "generate language codes(%s) error", *lang)
	}

	log.I("Run gsRPC Compile -- Success")
}
Esempio n. 3
0
func init() {
	gslogger.NewFlags(gslogger.ERROR | gslogger.INFO)

	var err error
	client, err = tcp.BuildClient(gorpc.BuildPipeline(eventLoop)).Connect("test")

	if err != nil {
		panic(err)
	}

	server = BindServer(0, client.Pipeline())
}
Esempio n. 4
0
func main() {

	gslogger.NewFlags(gslogger.ERROR | gslogger.INFO)

	var eventLoop = gorpc.NewEventLoop(uint32(runtime.NumCPU()), 2048, 500*time.Millisecond)

	tcp.NewServer(
		gorpc.BuildPipeline(eventLoop),
	).EvtNewPipeline(tcp.EvtNewPipeline(func(pipeline gorpc.Pipeline) {
		pipeline.AddService(rpctest.MakeServer(0, &_MockServer{}))
	})).Listen(":13512")
}
Esempio n. 5
0
func (runner *_Runner) Run(main func(runner Runner)) {
	defer func() {
		if e := recover(); e != nil {
			runner.E("catch unknown exception\n\t%s", e)
		}

		runner.I("service stopped.")

		gslogger.Join()
	}()

	flag.Parse()

	configpath := *runner.flagString["config"]

	runner.D("config file path :%s", configpath)

	if configpath != "" {
		switch filepath.Ext(configpath) {
		case ".json":
			if err := gsconfig.LoadJSON(configpath); err != nil {
				gserrors.Panicf(ErrConfig, "load config file error :%s", configpath)
			}
		default:
			runner.W("can't load config file :%s", configpath)
		}
	}

	for k, v := range runner.flagString {
		gsconfig.Update(runner.fullname[k], *v)
	}
	for k, v := range runner.flagInt {
		gsconfig.Update(runner.fullname[k], *v)
	}
	for k, v := range runner.flagUint {
		gsconfig.Update(runner.fullname[k], *v)
	}
	for k, v := range runner.flagFloat32 {
		gsconfig.Update(runner.fullname[k], *v)
	}
	for k, v := range runner.flagFloat64 {
		gsconfig.Update(runner.fullname[k], *v)
	}
	for k, v := range runner.flagSecond {
		gsconfig.Update(runner.fullname[k], *v)
	}
	for k, v := range runner.flagMilliseconds {
		gsconfig.Update(runner.fullname[k], *v)
	}

	logroot := gsconfig.String("gsrunner.log", "")
	runner.D("log root path :%s", logroot)
	loglevel := gsconfig.String("gsrunner.log.level", "")
	runner.D("log level :%s", loglevel)
	registryFile := gsconfig.String("gsrunner.registry", "")
	runner.D("registry file:%s", registryFile)

	if logroot != "" {

		fullpath, _ := filepath.Abs(logroot)

		dir := filepath.Dir(fullpath)

		name := filepath.Base(fullpath)

		gslogger.SetLogDir(dir)

		gslogger.NewSink(gslogger.NewFilelog("gschat-mailhub", name, gsconfig.Int64("gschat.mailhub.log.maxsize", 0)))
	}

	if loglevel != "" {
		gslogger.NewFlags(gslogger.ParseLevel(loglevel))
	}

	if registryFile != "" {

		runner.I("load gsrpc services registry file :%s", registryFile)

		file, err := os.Open(registryFile)

		if err != nil {
			gserrors.Panicf(err, "open registry file error :%s", registryFile)
		}

		gorpc.RegistryLoad(file, registryFile)

		runner.I("load gsrpc services registry file :%s -- success", registryFile)
	}

	runner.I("service started.")

	main(runner)
}