本文整理匯總了Golang中github.com/yvasiyarov/swagger/parser.Parser.GetResourceListingJson方法的典型用法代碼示例。如果您正苦於以下問題:Golang Parser.GetResourceListingJson方法的具體用法?Golang Parser.GetResourceListingJson怎麽用?Golang Parser.GetResourceListingJson使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/yvasiyarov/swagger/parser.Parser
的用法示例。
在下文中一共展示了Parser.GetResourceListingJson方法的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
}