RegisterBuiltinVirtualFile registers an embedded file under a canonical builtin path. Paths must start with BuiltinPathPrefix ("@builtin:"); it panics if they do not. If the same path is registered twice with identical content the call is a no-op. Registering the same path with different content pan
(path string, content []byte)
| 25 | // Registering the same path with different content panics to surface configuration errors early. |
| 26 | // This function is safe for concurrent use. |
| 27 | func RegisterBuiltinVirtualFile(path string, content []byte) { |
| 28 | if !strings.HasPrefix(path, BuiltinPathPrefix) { |
| 29 | panic(fmt.Sprintf("RegisterBuiltinVirtualFile: path %q does not start with %q", path, BuiltinPathPrefix)) |
| 30 | } |
| 31 | builtinVirtualFilesMu.Lock() |
| 32 | defer builtinVirtualFilesMu.Unlock() |
| 33 | if builtinVirtualFiles == nil { |
| 34 | builtinVirtualFiles = make(map[string][]byte) |
| 35 | } |
| 36 | if existing, ok := builtinVirtualFiles[path]; ok { |
| 37 | if string(existing) != string(content) { |
| 38 | panic(fmt.Sprintf("RegisterBuiltinVirtualFile: path %q already registered with different content", path)) |
| 39 | } |
| 40 | return // idempotent: same content, no-op |
| 41 | } |
| 42 | virtualFsLog.Printf("Registering builtin virtual file: %s (%d bytes)", path, len(content)) |
| 43 | builtinVirtualFiles[path] = content |
| 44 | } |
| 45 | |
| 46 | // BuiltinVirtualFileExists returns true if the given path is registered as a builtin virtual file. |
| 47 | func BuiltinVirtualFileExists(path string) bool { |