当前位置: 首页>>代码示例>>Golang>>正文


Golang gserrors.Panicf函数代码示例

本文整理汇总了Golang中github.com/gsdocker/gserrors.Panicf函数的典型用法代码示例。如果您正苦于以下问题:Golang Panicf函数的具体用法?Golang Panicf怎么用?Golang Panicf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Panicf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Contract

func (codegen *_CodeGen) Contract(compiler *gslang.Compiler, contract *ast.Contract) {

	var buff bytes.Buffer

	if err := codegen.tpl.ExecuteTemplate(&buff, "contract", contract); err != nil {
		gserrors.Panicf(err, "exec template(contract) for %s error", contract)
	}

	codegen.writeJavaFile(contract.Name(), contract, buff.Bytes())

	buff.Reset()

	if err := codegen.tpl.ExecuteTemplate(&buff, "dispatcher", contract); err != nil {
		gserrors.Panicf(err, "exec template(contract) for %s error", contract)
	}

	codegen.writeJavaFile(contract.Name()+"Dispatcher", contract, buff.Bytes())

	buff.Reset()

	if err := codegen.tpl.ExecuteTemplate(&buff, "rpc", contract); err != nil {
		gserrors.Panicf(err, "exec template(contract) for %s error", contract)
	}

	codegen.writeJavaFile(contract.Name()+"RPC", contract, buff.Bytes())
}
开发者ID:gsrpc,项目名称:gsrpc,代码行数:26,代码来源:codegen.go

示例2: writeJavaFile

func (codegen *_CodeGen) writeJavaFile(name string, expr ast.Expr, content []byte) {

	var buff bytes.Buffer

	jPackageName := javaPackageName(codegen.packageName)

	packagename := strings.Replace(jPackageName, ".", "/", -1)

	fullpath := filepath.Join(codegen.rootpath, packagename, name+".java")

	buff.WriteString(fmt.Sprintf("package %s;\n\n", jPackageName))

	for _, i := range codegen.imports {

		if name == "EvtRPC" {
			codegen.I("%s", i)
		}

		buff.WriteString(fmt.Sprintf("%s;\n\n", i))

	}

	buff.Write(content)

	if err := os.MkdirAll(filepath.Dir(fullpath), 0755); err != nil {
		gserrors.Panicf(err, "create output directory error")
	}

	codegen.D("write file :%s", fullpath)

	if err := ioutil.WriteFile(fullpath, buff.Bytes(), 0644); err != nil {
		gserrors.Panicf(err, "write generate stub code error")
	}
}
开发者ID:gsrpc,项目名称:gsrpc,代码行数:34,代码来源:codegen.go

示例3: main

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")
}
开发者ID:gsrpc,项目名称:gsrpc,代码行数:58,代码来源:main.go

示例4: Load

func (registry *_Registry) Load(origin io.Reader, name string) {
	reader := bufio.NewReader(origin)

	lines := 0

	items := make(map[string]uint16)

	for {
		line, err := reader.ReadString('\n')

		if err != nil {
			if err == io.EOF {
				break
			}

			gserrors.Panicf(err, "read registry file error :%s", name)
		}

		tokens := registryRegex.FindStringSubmatch(line)

		if tokens == nil {
			gserrors.Panicf(ErrRegistry, "load registry file error: invalid format\n\t%s(%d)", name, lines)
		}

		serviceName := ""

		serviceID := uint16(0)

		for i, name := range registryRegex.SubexpNames() {
			if name == "name" {
				serviceName = tokens[i]
			}

			if name == "id" {
				val, err := strconv.ParseInt(tokens[i], 0, 32)

				if err != nil {
					gserrors.Panicf(err, "load registry file error: invalid format\n\t%s(%d)", name, lines)
				}

				if val > math.MaxUint16 {
					gserrors.Panicf(ErrRegistry, "load registry file error: id out of range\n\t%s(%d)", name, lines)
				}

				serviceID = uint16(val)
			}
		}

		items[serviceName] = serviceID

		lines++

	}

	registry.Update(items)
}
开发者ID:gsrpc,项目名称:gorpc,代码行数:56,代码来源:registry.go

示例5: defaultVal

func (codegen *_CodeGen) defaultVal(typeDecl ast.Type) string {

	switch typeDecl.(type) {
	case *ast.BuiltinType:
		builtinType := typeDecl.(*ast.BuiltinType)
		return defaultval[builtinType.Type]
	case *ast.TypeRef:
		typeRef := typeDecl.(*ast.TypeRef)

		return codegen.defaultVal(typeRef.Ref)

	case *ast.Enum:

		enum := typeDecl.(*ast.Enum)

		prefix, name := codegen.typeRef(typeDecl.Package(), typeDecl.FullName())

		if prefix != "" {
			return prefix + "." + name + "" + enum.Constants[0].Name()
		}

		return name + "" + enum.Constants[0].Name()

	case *ast.Table:

		prefix, name := codegen.typeRef(typeDecl.Package(), typeDecl.FullName())

		if prefix != "" {
			return prefix + ".New" + name + "()"
		}

		return "New" + name + "()"

	case *ast.Seq:
		seq := typeDecl.(*ast.Seq)

		if seq.Size != -1 {

			var buff bytes.Buffer

			if err := codegen.tpl.ExecuteTemplate(&buff, "create_array", seq); err != nil {
				gserrors.Panicf(err, "exec template(create_array) for %s errir", seq)
			}

			return buff.String()
		}

		return "nil"
	}

	gserrors.Panicf(nil, "typeName  error: unsupport type(%s)", typeDecl)

	return "unknown"
}
开发者ID:gsrpc,项目名称:gsrpc,代码行数:54,代码来源:codegen.go

示例6: checkName

func (runner *_Runner) checkName(name, fullname string) {
	if _, ok := runner.fullname[name]; ok {
		gserrors.Panicf(ErrFlag, "duplicate flag name :%s", name)
	}

	for _, v := range runner.fullname {
		if v == fullname {
			gserrors.Panicf(ErrFlag, "duplicate flag fullname :%s", fullname)
		}
	}

	runner.fullname[name] = fullname
}
开发者ID:gsdocker,项目名称:gsrunner,代码行数:13,代码来源:runner.go

示例7: writefile

func (codegen *_CodeGen) writefile(bytes []byte, extend string) {

	path := strings.Replace(codegen.script.Package, ".", "/", -1)

	fullpath := filepath.Join(codegen.rootpath, path, filepath.Base(codegen.script.Name())+extend)

	if err := os.MkdirAll(filepath.Dir(fullpath), 0755); err != nil {
		gserrors.Panicf(err, "create output directory error")
	}

	if err := ioutil.WriteFile(fullpath, bytes, 0644); err != nil {
		gserrors.Panicf(err, "write generate stub code error")
	}
}
开发者ID:gsrpc,项目名称:gsrpc,代码行数:14,代码来源:codegen.go

示例8: tagValue

func (codegen *_CodeGen) tagValue(typeDecl ast.Type) string {
	switch typeDecl.(type) {
	case *ast.BuiltinType:
		builtinType := typeDecl.(*ast.BuiltinType)

		switch builtinType.Type {
		case lexer.KeySByte, lexer.KeyByte, lexer.KeyBool:
			return "GSTagI8"
		case lexer.KeyInt16, lexer.KeyUInt16:
			return "GSTagI16"
		case lexer.KeyInt32, lexer.KeyUInt32, lexer.KeyFloat32:
			return "GSTagI32"
		case lexer.KeyInt64, lexer.KeyUInt64, lexer.KeyFloat64:
			return "GSTagI64"
		case lexer.KeyString:
			return "GSTagString"
		}

	case *ast.TypeRef:
		return codegen.tagValue(typeDecl.(*ast.TypeRef).Ref)
	case *ast.Enum:

		_, ok := gslang.FindAnnotation(typeDecl, "gslang.Flag")

		if !ok {
			return "GSTagI32"
		}

		return "GSTagI8"

	case *ast.Table:
		return "GSTagTable"
	case *ast.Seq:

		seq := typeDecl.(*ast.Seq)

		component := codegen.tagValue(seq.Component)

		if component == "GSTagList" {
			start, _ := gslang.Pos(typeDecl)
			gserrors.Panicf(nil, "list component %v can't be a list :%v", seq.Component, start)
		}

		return fmt.Sprintf("((%s << 4)|GSTagList)", component)
	}

	gserrors.Panicf(nil, "typeName  error: unsupport type(%s)", typeDecl)

	return ""
}
开发者ID:gsrpc,项目名称:gsrpc,代码行数:50,代码来源:codegen.go

示例9: Enum

func (codegen *_CodeGen) Enum(compiler *gslang.Compiler, enum *ast.Enum) {

	if err := codegen.tpl.ExecuteTemplate(&codegen.predecl, "enum_predecl", enum); err != nil {
		gserrors.Panicf(err, "exec template(enum_predecl) for %s error", enum)
	}

	if err := codegen.tpl.ExecuteTemplate(&codegen.header, "enum_header", enum); err != nil {
		gserrors.Panicf(err, "exec template(Enum) for %s error", enum)
	}

	if err := codegen.tpl.ExecuteTemplate(&codegen.source, "enum_source", enum); err != nil {
		gserrors.Panicf(err, "exec template(Enum) for %s error", enum)
	}
}
开发者ID:gsrpc,项目名称:gsrpc,代码行数:14,代码来源:codegen.go

示例10: Table

func (codegen *_CodeGen) Table(compiler *gslang.Compiler, tableType *ast.Table) {

	if err := codegen.tpl.ExecuteTemplate(&codegen.predecl, "table_predecl", tableType); err != nil {
		gserrors.Panicf(err, "exec template(table_predecl) for %s error", tableType)
	}

	if err := codegen.tpl.ExecuteTemplate(&codegen.header, "table_header", tableType); err != nil {

		gserrors.Panicf(err, "exec template(table) for %s error", tableType)
	}

	if err := codegen.tpl.ExecuteTemplate(&codegen.source, "table_source", tableType); err != nil {
		gserrors.Panicf(err, "exec template(table) for %s error", tableType)
	}
}
开发者ID:gsrpc,项目名称:gsrpc,代码行数:15,代码来源:codegen.go

示例11: objTypeName

func (codegen *_CodeGen) objTypeName(typeDecl ast.Type) string {
	switch typeDecl.(type) {
	case *ast.BuiltinType:
		builtinType := typeDecl.(*ast.BuiltinType)

		return builtinObj[builtinType.Type]
	case *ast.TypeRef:
		typeRef := typeDecl.(*ast.TypeRef)

		return codegen.typeName(typeRef.Ref)

	case *ast.Enum, *ast.Table:
		prefix, name := codegen.typeRef(typeDecl.Package(), typeDecl.FullName())

		if prefix != "" {
			return prefix + "." + name
		}

		return name

	case *ast.Seq:
		seq := typeDecl.(*ast.Seq)

		return fmt.Sprintf("%s[]", codegen.typeName(seq.Component))
	}

	gserrors.Panicf(nil, "typeName  error: unsupport type(%s)", typeDecl)

	return "unknown"
}
开发者ID:gsrpc,项目名称:gsrpc,代码行数:30,代码来源:codegen.go

示例12: typeName

func (codegen *_CodeGen) typeName(typeDecl ast.Type) string {
	switch typeDecl.(type) {
	case *ast.BuiltinType:
		builtinType := typeDecl.(*ast.BuiltinType)

		return builtin[builtinType.Type]
	case *ast.TypeRef:
		typeRef := typeDecl.(*ast.TypeRef)

		return codegen.typeName(typeRef.Ref)

	case *ast.Enum, *ast.Table:
		_, name := codegen.typeRef(typeDecl.Package(), typeDecl.FullName())

		if gslang.IsException(typeDecl) {
			return exception(name)
		}

		return name

	case *ast.Seq:
		seq := typeDecl.(*ast.Seq)

		return fmt.Sprintf("%s[]", codegen.typeName(seq.Component))
	}

	gserrors.Panicf(nil, "typeName  error: unsupport type(%s)", typeDecl)

	return "unknown"
}
开发者ID:gsrpc,项目名称:gsrpc,代码行数:30,代码来源:codegen.go

示例13: TestParser

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)
	}
}
开发者ID:gsrpc,项目名称:gslang,代码行数:32,代码来源:gslang_test.go

示例14: EndScript

// EndScript .
func (codegen *_CodeGen) EndScript(compiler *gslang.Compiler) {

	content := codegen.content.String()

	packageName := codegen.script.Package

	if packageName == "com.gsrpc" {
		content = strings.Replace(content, "gorpc.", "", -1)
	}

	for k, v := range imports {
		if strings.Contains(content, k) {
			codegen.header.WriteString(fmt.Sprintf("import \"%s\"\n", v))
		}
	}

	codegen.header.WriteString(content)

	var err error
	var sources []byte

	fullpath := filepath.Join(codegen.rootpath, codegen.scriptPath, filepath.Base(codegen.script.Name())+".go")

	sources, err = format.Source(codegen.header.Bytes())

	if err != nil {
		gserrors.Panicf(err, "format golang source codes error:%s", fullpath)
	}

	codegen.D("generate golang file :%s", fullpath)

	if !fs.Exists(filepath.Dir(fullpath)) {
		err := os.MkdirAll(filepath.Dir(fullpath), 0755)

		if err != nil {
			gserrors.Panicf(err, "format golang source codes error")
		}
	}

	err = ioutil.WriteFile(fullpath, sources, 0644)

	if err != nil {
		gserrors.Panicf(err, "write generate golang file error")
	}
}
开发者ID:gsrpc,项目名称:gsrpc,代码行数:46,代码来源:codegen.go

示例15: Next

func (dataset *_DataSet) Next() (data []byte, version uint64) {
	select {
	case val := <-dataset.Q:
		return val.Content, val.ID
	case <-dataset.closed:
		gserrors.Panicf(ErrOp, "call Next on closed dataset")
		return nil, 0
	}
}
开发者ID:gschat,项目名称:tsdb,代码行数:9,代码来源:dataset.go


注:本文中的github.com/gsdocker/gserrors.Panicf函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。