本文整理汇总了Golang中github.com/babelrpc/babel/idl.Idl类的典型用法代码示例。如果您正苦于以下问题:Golang Idl类的具体用法?Golang Idl怎么用?Golang Idl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Idl类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: allServices
func allServices(pidl *idl.Idl) []*idl.Service {
s := make([]*idl.Service, 0)
s = append(s, pidl.Services...)
for _, i := range pidl.UniqueImports() {
s = append(s, i.Services...)
}
return s
}
开发者ID:babelrpc,项目名称:babel,代码行数:8,代码来源:handlers.go
示例2: allStructs
func allStructs(pidl *idl.Idl) []*idl.Struct {
s := make([]*idl.Struct, 0)
s = append(s, pidl.Structs...)
for _, i := range pidl.UniqueImports() {
s = append(s, i.Structs...)
}
return s
}
开发者ID:babelrpc,项目名称:babel,代码行数:8,代码来源:helpers.go
示例3: allEnums
func allEnums(pidl *idl.Idl) []*idl.Enum {
s := make([]*idl.Enum, 0)
s = append(s, pidl.Enums...)
for _, i := range pidl.UniqueImports() {
s = append(s, i.Enums...)
}
return s
}
开发者ID:babelrpc,项目名称:babel,代码行数:8,代码来源:helpers.go
示例4: loadBabelFiles
func loadBabelFiles(args []string) (*idl.Idl, error) {
// initialize map to track processed files
processedFiles := make(map[string]bool)
// create base IDL to aggregate into
var midl idl.Idl
midl.Init()
midl.AddDefaultNamespace("babelrpc.io", "Foo/Bar")
// load specified IDL files into it
for _, infilePat := range args {
infiles, err := filepath.Glob(infilePat)
if err != nil {
return nil, errors.New(fmt.Sprintf("Cannot glob files: %s\n", err))
}
if len(infiles) == 0 {
log.Printf("Warning: No files match \"%s\"\n", infilePat)
}
for _, infile := range infiles {
_, ok := processedFiles[infile]
if ok {
log.Printf("Already processed %s\n", infile)
} else {
processedFiles[infile] = true
// fmt.Printf("%s:\n", infile)
bidl, err := parser.ParseIdl(infile, "test")
if err != nil {
return nil, errors.New(fmt.Sprintf("Parsing error in %s: %s\n", infile, err))
}
midl.Imports = append(midl.Imports, bidl)
}
}
}
// validate combined babel
err := midl.Validate("test")
if err != nil {
log.Printf("Warning: Combined IDL does not validate: %s\n", err)
}
return &midl, nil
}
开发者ID:babelrpc,项目名称:babel,代码行数:43,代码来源:handlers.go
示例5: typeToItems
func typeToItems(pidl *idl.Idl, t *idl.Type) *swagger2.ItemsDef {
it := new(swagger2.ItemsDef)
it.Ref = ""
if t.IsPrimitive() {
it.Format = t.String()
if t.IsInt() || t.IsByte() {
it.Type = "integer"
it.Format = "int32"
if t.Name == "int64" {
if swagInt && restful {
// Swagger style int64
it.Format = "int64"
} else {
// Babel style int64
it.Type = "string" // ??? Babel quotes large integers to avoid precision loss in JavaScript
it.Format = "int64" // SWAGGER-CLARIFICATION: is format int64 legal with type string?
}
}
} else if t.IsFloat() {
it.Type = "number"
it.Format = "float"
if t.Name == "float64" {
it.Format = "double"
}
} else if t.IsBool() {
it.Type = "boolean"
it.Format = ""
} else if t.IsDatetime() {
it.Type = "string"
it.Format = "date-time"
} else if t.IsDecimal() {
it.Type = "string"
it.Format = ""
} else if t.IsString() || t.IsChar() {
it.Type = "string"
it.Format = ""
}
} else if t.IsBinary() {
it.Type = "string"
it.Format = "byte"
} else if t.IsMap() {
it.Type = "object"
// hmmm....what to do if keytype is not string?
// SWAGGER-CLARIFICATION: Does swagger require all key types to be strings?
it.AdditionalProperties = typeToItems(pidl, t.ValueType)
} else if t.IsList() {
it.Type = "array"
it.Format = ""
it.Items = typeToItems(pidl, t.ValueType)
} else if t.IsEnum(pidl) {
// SWAGGER-BUG: Enums cannot be delared in a schema
it.Type = "string"
it.Format = ""
it.Enum = make([]interface{}, 0)
e := pidl.FindEnum(t.Name)
if e != nil {
for _, x := range e.Values {
it.Enum = append(it.Enum, x.Name)
}
}
} else {
// user-defined, struct or enum
it.Ref = "#/definitions/" + t.Name
}
return it
}
开发者ID:babelrpc,项目名称:babel,代码行数:66,代码来源:helpers.go
示例6: main
// main entry point
func main() {
/*
// recover panicking parser
defer func() {
if r := recover(); r != nil {
e, y := r.(*idl.Error)
if y {
fmt.Fprintln(os.Stderr, e.Error())
os.Exit(e.Code)
} else {
fmt.Fprintf(os.Stderr, "Exiting due to fatal error:\n%s\n", r)
os.Exit(1)
}
}
}()
*/
var format string
flag.StringVar(&format, "format", "json", "Specifies output format - can be json or yaml")
var output string
flag.StringVar(&output, "out", "", "Specifies the file to write to")
var host string
flag.StringVar(&host, "host", "localhost", "Specifies the host to include in the file, for example localhost:8080")
var basePath string
flag.StringVar(&basePath, "basepath", "/", "Specifies the base path to include in the file, for example /foo/bar")
var title string
flag.StringVar(&title, "title", "My Application", "Sets the application title")
flag.BoolVar(&flatten, "flat", false, "Flatten composed objects into a single object definition")
var version string
flag.StringVar(&version, "version", "1.0", "Sets the API version")
flag.BoolVar(&restful, "rest", false, "Process @rest annotations (resulting Swagger won't be able to invoke Babel services)")
flag.BoolVar(&swagInt, "int64", false, "When -rest is enabled, format int64 Swagger-style instead of Babel-style")
flag.BoolVar(&genErr, "error", false, "When -rest is enabled, still include the Babel error definition")
flag.Parse()
if format != "json" && format != "yaml" {
fmt.Printf("-format must be json or yaml.\n")
os.Exit(0)
}
if swagInt && !restful {
fmt.Fprintf(os.Stderr, "Warning: Ignoring -int64 because -rest is not set.\n")
swagInt = false
}
if len(flag.Args()) == 0 {
fmt.Printf("Please specify files to process or -help for options.\n")
os.Exit(0)
}
// initialize map to track processed files
processedFiles := make(map[string]bool)
// create base IDL to aggregate into
var midl idl.Idl
midl.Init()
midl.AddDefaultNamespace("babelrpc.io", "Foo/Bar")
// load specified IDL files into it
for _, infilePat := range flag.Args() {
infiles, err := filepath.Glob(infilePat)
if err != nil {
fmt.Fprintf(os.Stderr, "Cannot glob files: %s\n", err)
os.Exit(5)
}
if len(infiles) == 0 {
fmt.Fprintf(os.Stderr, "Warning: No files match \"%s\"\n", infilePat)
}
for _, infile := range infiles {
_, ok := processedFiles[infile]
if ok {
fmt.Fprintf(os.Stderr, "Already processed %s\n", infile)
} else {
processedFiles[infile] = true
// fmt.Printf("%s:\n", infile)
bidl, err := parser.ParseIdl(infile, "test")
if err != nil {
fmt.Fprintf(os.Stderr, "Parsing error in %s: %s\n", infile, err)
os.Exit(6)
}
midl.Imports = append(midl.Imports, bidl)
}
}
}
// validate combined babel
err := midl.Validate("test")
if err != nil {
//.........这里部分代码省略.........
开发者ID:babelrpc,项目名称:babel,代码行数:101,代码来源:main.go
注:本文中的github.com/babelrpc/babel/idl.Idl类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论