MCPcopy
hub / github.com/swaggo/swag / getCodeExampleForSummary

Function getCodeExampleForSummary

operation.go:1225–1255  ·  view source on GitHub ↗
(summaryName string, dirPath string)

Source from the content-addressed store, hash-verified

1223}
1224
1225func getCodeExampleForSummary(summaryName string, dirPath string) ([]byte, error) {
1226 dirEntries, err := os.ReadDir(dirPath)
1227 if err != nil {
1228 return nil, err
1229 }
1230
1231 for _, entry := range dirEntries {
1232 if entry.IsDir() {
1233 continue
1234 }
1235
1236 fileName := entry.Name()
1237
1238 if !strings.Contains(fileName, ".json") {
1239 continue
1240 }
1241
1242 if strings.Contains(fileName, summaryName) {
1243 fullPath := filepath.Join(dirPath, fileName)
1244
1245 commentInfo, err := os.ReadFile(fullPath)
1246 if err != nil {
1247 return nil, fmt.Errorf("Failed to read code example file %s error: %s ", fullPath, err)
1248 }
1249
1250 return commentInfo, nil
1251 }
1252 }
1253
1254 return nil, fmt.Errorf("unable to find code example file for tag %s in the given directory", summaryName)
1255}

Callers 1

ParseCodeSampleMethod · 0.85

Calls 2

IsDirMethod · 0.80
NameMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…