示例#1
0
func TestParser(t *testing.T) {

	defer gslogger.Join()

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

	err := compiler.Compile("test.gs")

	if err != nil {
		t.Fatal(err)
	}

	err = compiler.Compile("../gslang.gs")

	if err != nil {
		t.Fatal(err)
	}

	err = compiler.Compile("../annotations.gs")

	if err != nil {
		t.Fatal(err)
	}

	err = compiler.Link()

	if err != nil {
		t.Fatal(err)
	}
}
示例#2
0
文件: main.go 项目: 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")
}
示例#3
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)
}