Go coding standards and idioms for this project. Use when writing or reviewing Go code, adding new handlers, or modifying the Markdown parser.
This is a single-file Go HTTP server. All code lives in main.go.
fmt.Errorf for wrapped errors with contexthttp.Error() for client errors, log server errors// Good
if err != nil {
return fmt.Errorf("failed to read file %s: %w", path, err)
}
// Bad
if err != nil {
return err
}
fmt.Printf("[%s] %s %s\n", time.Now().Format("15:04:05"), r.Method, r.URL.String())filepath.Clean() before useContent-Type headersstrings.Builder for building HTML/text outputfmt.Sprintf for simple formattinghtml.EscapeString()FindStringSubmatch to extract groupsReplaceAllStringFunc for complex replacementsFunctions should follow this order:
main()renderFile() switch statementrenderXXX(content string) string functionbuildHTML() if neededLocation: renderMarkdown() function (~350 lines)
processInline() closure