本文整理汇总了Golang中github.com/yvasiyarov/swagger/parser.Parser类的典型用法代码示例。如果您正苦于以下问题:Golang Parser类的具体用法?Golang Parser怎么用?Golang Parser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Parser类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: generateSwaggerDocs
func generateSwaggerDocs(parser *parser.Parser) {
fd, err := os.Create(path.Join(*outputSpec, "docs.go"))
if err != nil {
log.Fatalf("Can not create document file: %v\n", err)
}
defer fd.Close()
var apiDescriptions bytes.Buffer
for apiKey, apiDescription := range parser.TopLevelApis {
apiDescriptions.WriteString("\"" + apiKey + "\":")
apiDescriptions.WriteString("`")
json, err := json.MarshalIndent(apiDescription, "", " ")
if err != nil {
log.Fatalf("Can not serialise []ApiDescription to JSON: %v\n", err)
}
apiDescriptions.Write(json)
apiDescriptions.WriteString("`,")
}
doc := strings.Replace(generatedFileTemplate, "{{resourceListing}}", "`"+string(parser.GetResourceListingJson())+"`", -1)
doc = strings.Replace(doc, "{{apiDescriptions}}", "map[string]string{"+apiDescriptions.String()+"}", -1)
fd.WriteString(doc)
}
示例2: generateSwaggerUiFiles
func generateSwaggerUiFiles(parser *parser.Parser) error {
fd, err := os.Create(path.Join(*outputSpec, "index.json"))
if err != nil {
return fmt.Errorf("Can not create the master index.json file: %v\n", err)
}
defer fd.Close()
fd.WriteString(string(parser.GetResourceListingJson()))
for apiKey, apiDescription := range parser.TopLevelApis {
err = os.MkdirAll(path.Join(*outputSpec, apiKey), 0777)
if err != nil {
return err
}
fd, err = os.Create(path.Join(*outputSpec, apiKey, "index.json"))
if err != nil {
return fmt.Errorf("Can not create the %s/index.json file: %v\n", apiKey, err)
}
defer fd.Close()
json, err := json.MarshalIndent(apiDescription, "", " ")
if err != nil {
return fmt.Errorf("Can not serialise []ApiDescription to JSON: %v\n", err)
}
fd.Write(json)
log.Printf("Wrote %v/index.json", apiKey)
}
return nil
}