本文整理匯總了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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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 {
//.........這裏部分代碼省略.........