MCPcopy Create free account
hub / github.com/bufbuild/buf / FileTypeForPath

Function FileTypeForPath

private/bufpkg/bufmodule/file_type.go:83–94  ·  view source on GitHub ↗

FileTypeForPath returns the FileType for the given path. Returns error if the path cannot be classified as a FileType, that is if it is not a .proto file, license file, or documentation file. Note that license and documentation files must be at the root, and cannot be in subdirectories. That is, s

(path string)

Source from the content-addressed store, hash-verified

81// Note that license and documentation files must be at the root, and cannot be in subdirectories. That is,
82// subdir/LICENSE will not be classified as a FileTypeLicense, but LICENSE will be.
83func FileTypeForPath(path string) (FileType, error) {
84 if normalpath.Ext(path) == ".proto" {
85 return FileTypeProto, nil
86 }
87 if path == licenseFilePath {
88 return FileTypeLicense, nil
89 }
90 if _, ok := docFilePathMap[path]; ok {
91 return FileTypeDoc, nil
92 }
93 return 0, fmt.Errorf("could not classify FileType for path %q", path)
94}
95
96// IsValidModuleFilePath returns true if the given file path is a valid Module file path.
97//

Calls 1

ExtFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…