| name | go-standards |
| description | Go coding standards and idioms for this project. Use when writing or reviewing Go code, adding new handlers, or modifying the Markdown parser. Use when this capability is needed. |
| metadata | {"author":"feraudet"} |
Go Standards
Project Conventions
This is a single-file Go HTTP server. All code lives in main.go.
Error Handling
- Return early on errors with descriptive messages
- Use
fmt.Errorf for wrapped errors with context
- HTTP handlers: use
http.Error() for client errors, log server errors
if err != nil {
return fmt.Errorf("failed to read file %s: %w", path, err)
}
if err != nil {
return err
}
HTTP Handlers
- Log all requests with timestamp:
fmt.Printf("[%s] %s %s\n", time.Now().Format("15:04:05"), r.Method, r.URL.String())
- Clean paths with
filepath.Clean() before use
- Set appropriate
Content-Type headers
- Return early for special endpoints (asset, mtime)
String Building
- Use
strings.Builder for building HTML/text output
- Use
fmt.Sprintf for simple formatting
- Escape user content with
html.EscapeString()
Regex Patterns
- Compile regexes once at package level for reuse, or inline for clarity in small functions
- Use
FindStringSubmatch to extract groups
- Use
ReplaceAllStringFunc for complex replacements
Code Organization
Functions should follow this order:
- Package-level variables (constants, maps, structs)
- Helper functions (slugify, replaceEmojis, etc.)
main()
- HTTP handler
- Render functions by type (renderFile, renderMarkdown, renderJSON, etc.)
- HTML template builder
Adding New File Format Support
- Add case in
renderFile() switch statement
- Create
renderXXX(content string) string function
- Add CSS styles in
buildHTML() if needed
- Add format to CLAUDE.md supported formats table
Adding New Markdown Features
Location: renderMarkdown() function (~350 lines)
- Block elements: Add regex check in main loop before paragraph fallback
- Inline elements: Add to
processInline() closure
- Preserve order: math/code first (protect from other processing)
Converted and distributed by TomeVault — claim your Tome and manage your conversions.