=============== LIBRARY RULES =============== From library maintainers: - FIRST: Run `go doc -all github.com/dmitrymomot/foundation` to get the complete packages index with descriptions - THEN: Use `go doc -all github.com/dmitrymomot/foundation/core/binder` (example) for detailed package documentation - Core packages: core/router, core/handler, core/binder, core/response, core/session, core/validator, core/sanitizer - Middleware: github.com/dmitrymomot/foundation/middleware for CORS, JWT auth, rate limiting, security headers - Utilities: pkg/jwt, pkg/totp, pkg/webhook, pkg/async, pkg/ratelimiter, pkg/secrets, pkg/token - Database: integration/database/pg (PostgreSQL), integration/database/redis, integration/database/mongo - External services: integration/email/postmark, integration/email/smtp, integration/storage/s3 - Each package has comprehensive doc.go with examples - always check it first - Use generics: HandlerFunc[C Context] where C is custom context (e.g., *router.Context) - Configure with functional options: WithStore(), WithTimeout(), WithTransport() - Foundation requires Go 1.23+ for generics support - The main doc.go file contains full package list with import paths and descriptions ### Install foundation Library Source: https://github.com/dmitrymomot/foundation/blob/main/README.md Demonstrates how to add the foundation library to your Go project using the go get command. This is the primary method for incorporating the library's functionalities. ```bash go get github.com/dmitrymomot/foundation ``` -------------------------------- ### Go Web Server Setup and Routing Source: https://github.com/dmitrymomot/foundation/blob/main/README.md Demonstrates setting up a Go web server using the foundation library, including router initialization, middleware application (CORS, RequestID, Logging), and defining GET routes with custom handlers. It shows how to extract URL parameters and return JSON responses. ```go package main import ( "context" "log" "github.com/dmitrymomot/foundation/core/handler" "github.com/dmitrymomot/foundation/core/response" "github.com/dmitrymomot/foundation/core/router" "github.com/dmitrymomot/foundation/core/server" "github.com/dmitrymomot/foundation/middleware" ) func main() { // Create router with router.Context r := router.New[*router.Context]() // Add middleware r.Use(middleware.CORS[*router.Context]()) r.Use(middleware.RequestID[*router.Context]()) r.Use(middleware.Logging[*router.Context]()) // Define handlers that return Response functions r.Get("/", func(ctx *router.Context) handler.Response { return response.JSON(map[string]string{"status": "ok"}) }) r.Get("/users/{id}", func(ctx *router.Context) handler.Response { userID := ctx.Param("id") return response.JSON(map[string]string{ "user_id": userID, "message": "User found", }) }) // Create and run server ctx := context.Background() if err := server.Run(ctx, ":8080", r); err != nil { log.Fatal(err) } } ``` -------------------------------- ### Go Documentation Generation Source: https://github.com/dmitrymomot/foundation/blob/main/README.md Illustrates how to generate documentation for Go packages using the 'go doc' command. It shows commands for documenting a specific package and for generating comprehensive documentation including all exported symbols. ```bash go doc github.com/dmitrymomot/foundation/core/binder ``` ```bash go doc -all github.com/dmitrymomot/foundation/middleware ``` -------------------------------- ### Static Analysis with go vet Source: https://github.com/dmitrymomot/foundation/blob/main/AGENTS.md Runs the go vet command to statically analyze Go source code and report suspicious constructs. ```go go vet ./... ``` -------------------------------- ### Build and Test Commands for Foundation Project Source: https://github.com/dmitrymomot/foundation/blob/main/CLAUDE.md Provides essential bash commands for building and testing the foundation Go project. Includes running tests with race detection, executing specific tests, formatting code with `go fmt` and `goimports`, and static analysis with `go vet`. ```bash # Run tests with race detection go test -p 1 -count=1 -race -cover ./... # Run specific test go test -run TestName ./path/to/package # Format and check go fmt ./... goimports -w -local github.com/dmitrymomot/foundation . go vet ./... ``` -------------------------------- ### Generate Documentation with go doc Source: https://github.com/dmitrymomot/foundation/blob/main/AGENTS.md Generates documentation for Go packages. Can be used for specific packages or all packages within the project. ```go go doc github.com/dmitrymomot/foundation/ ``` ```go go doc -all ``` -------------------------------- ### Static Analysis with golangci-lint Source: https://github.com/dmitrymomot/foundation/blob/main/AGENTS.md Executes the golangci-lint tool to perform a comprehensive static analysis of the Go project, enforcing coding standards and detecting potential issues. ```go golangci-lint run ``` -------------------------------- ### Format Code and Imports with goimports Source: https://github.com/dmitrymomot/foundation/blob/main/AGENTS.md Formats Go code and automatically organizes import statements, ensuring they are sorted and adhering to local project conventions. ```go goimports -w -local github.com/dmitrymomot/foundation . ``` -------------------------------- ### Format Code with go fmt Source: https://github.com/dmitrymomot/foundation/blob/main/AGENTS.md Applies standard Go code formatting to all files in the project. This ensures consistent style and readability. ```go go fmt ./... ``` -------------------------------- ### Run Tests with Race Detector and Coverage Source: https://github.com/dmitrymomot/foundation/blob/main/AGENTS.md Executes all tests in the project, enabling the race detector and coverage reporting. This command is recommended before pushing changes to mirror CI expectations. ```go go test -p 1 -count=1 -race -cover ./... ``` -------------------------------- ### Run Tests with Coverage Reporting Source: https://github.com/dmitrymomot/foundation/blob/main/AGENTS.md Executes tests and reports code coverage. This is useful for identifying parts of the codebase that are not adequately tested. ```go go test -cover ./... ``` -------------------------------- ### Access Package Documentation with go doc Source: https://github.com/dmitrymomot/foundation/blob/main/CLAUDE.md Demonstrates how to access comprehensive documentation for specific packages within the foundation repository using the `go doc` command. This includes accessing documentation for individual packages and for all exported identifiers within a package. ```bash go doc github.com/dmitrymomot/foundation/core/session go doc github.com/dmitrymomot/foundation/middleware go doc -all github.com/dmitrymomot/foundation/core/binder # Full docs ``` -------------------------------- ### Run Specific Test in a Package Source: https://github.com/dmitrymomot/foundation/blob/main/AGENTS.md Focuses test execution on a specific test function within a particular package. This is useful for iterative development and quick feedback loops. ```go go test ./pkg/totp -run TestGenerate ``` -------------------------------- ### General Email Styles Source: https://github.com/dmitrymomot/foundation/blob/main/core/email/templates/example.html Defines general styles for an email template, including margin and padding resets for body elements and ensuring box-sizing is set to border-box for consistent element sizing. ```css /* General styles */ body, table, td, div, p { margin: 0; padding: 0; box-sizing: border-box; } ``` -------------------------------- ### Responsive Email Styles Source: https://github.com/dmitrymomot/foundation/blob/main/core/email/templates/example.html Applies responsive styles to an email template for optimal viewing on different screen sizes. It targets specific elements like containers and images to adjust their width and height based on screen resolution. ```css /* Responsive styles */ @media screen and (max-width: 600px) { .container { width: 90% !important; } .responsive-image { width: 100% !important; height: auto !important; } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.