MCPcopy Create free account
hub / github.com/oapi-codegen/oapi-codegen / loadTemplateOverrides

Function loadTemplateOverrides

cmd/oapi-codegen/oapi-codegen.go:347–381  ·  view source on GitHub ↗
(templatesDir string)

Source from the content-addressed store, hash-verified

345}
346
347func loadTemplateOverrides(templatesDir string) (map[string]string, error) {
348 templates := make(map[string]string)
349
350 if templatesDir == "" {
351 return templates, nil
352 }
353
354 files, err := os.ReadDir(templatesDir)
355 if err != nil {
356 return nil, err
357 }
358
359 for _, f := range files {
360 // Recursively load subdirectory files, using the path relative to the templates
361 // directory as the key. This allows for overriding the files in the service-specific
362 // directories (e.g. echo, chi, fiber, etc.).
363 if f.IsDir() {
364 subFiles, err := loadTemplateOverrides(path.Join(templatesDir, f.Name()))
365 if err != nil {
366 return nil, err
367 }
368 for subDir, subFile := range subFiles {
369 templates[path.Join(f.Name(), subDir)] = subFile
370 }
371 continue
372 }
373 data, err := os.ReadFile(path.Join(templatesDir, f.Name()))
374 if err != nil {
375 return nil, err
376 }
377 templates[f.Name()] = string(data)
378 }
379
380 return templates, nil
381}
382
383// detectPackageName detects and sets PackageName if not already set.
384func detectPackageName(cfg *configuration) error {

Callers 2

updateConfigFromFlagsFunction · 0.85
newConfigFromOldConfigFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…