# Packages
# README
Web Application Scaffolding with Echo Framework
This repository contains a boilerplate for a basic MVC style web application using the Echo Framework. The application utilizes native Go templates for rendering views, ensuring efficient server-side HTML generation. It also includes an example model, controller, and view for a user registration and authentication system with JSON Web Tokens for authentication.
Features
ā”ļø Web Components: Utilizes native Web Components for encapsulated and reusable UI elements.
š§ Vanilla JavaScript Controllers: Implements JavaScript controllers for handling user interactions and extending functionality.
āļø Air: A lightweight development server that automatically reloads the application when files are modified.
š Echo: A lightweight web framework for Go that provides a fast and efficient way to build web applications.
š Templates: Utilizes Go's native templating system to generate HTML content.
š Let's Encrypt: Automatically manages SSL certificates for HTTPS connections.
Getting Started
- Clone the repository:
git clone https://github.com/buelbuel/gowc.git cd gowc
- Install dependencies:
go mod download go install github.com/air-verse/air@latest
- Run the application:
air
- Access the application at http://localhost:4000
Configuration
Below are the available configuration options in config.toml:
- ServerAddress: The address the server listens on.
- StaticPaths: A map of routes to static file directories.
- UseLogger: Whether to use the logger middleware.
- LogOutput: Specifies where to output logs ("stdout", "stderr", or "file").
- LogFile: Path to the log file when LogOutput is set to "file".
- ColorizeLogger: Whether to colorize log output.
- UseTLS: Whether to use TLS with provided certificate and key files.
- UseAutoTLS: Whether to use Let's Encrypt for automatic TLS.
- CertFile: Path to the TLS certificate file.
- KeyFile: Path to the TLS key file.
- Domain: Domain name for Let's Encrypt.
- CacheDir: Directory to cache Let's Encrypt certificates.
- EnableCORS: Whether to enable CORS.
- CORSAllowOrigins: List of allowed origins for CORS.
- CORSAllowMethods: List of allowed methods for CORS.
- RateLimit: Rate limiting requests per second.
- RateBurst: Maximum burst for rate limiter.
Notes
- CORS is disabled by default. You may need CORS for API endpoints or for local development, depending on your use case. To enable CORS, set
EnableCors
to true. - The application uses PostgreSQL as the database. You can easily replace the database with any other database of your choice.
- To enable AutoTLS with Let's Encrypt, enable it in config.toml and set the domain as well as cache directory.
- To enable TLS without AutoTLS, set
UseTLS
totrue
and provide paths to the certificate and key files. You can generate a self-signed certificate using the following command:
go run $GOROOT/src/crypto/tls/generate_cert.go --host localhost
View Rendering
The application uses Go's native templating system, which is both powerful and flexible. This allows for dynamic HTML content generation based on server-side logic and data. The templates are defined in the views
directory and are rendered using Echo's built-in renderer.
JavaScript Controllers
Vanilla JavaScript controllers are implemented to handle user interactions and extend functionality. These controllers are defined in the public/controllers
directory.
CSS Preprocessors
Since modern CSS allows for most needed functionality like nesting, variables and more, a preprocessor is not needed in most cases. However, If you want to ensure backwards compatibility and need more extensive features, you can include any preprocessor like SASS or LESS in the air build step. See the comments in air.toml.
Directory Structure
The default structure of a new project is as follows:
āāā cmd
ā āāā doc.go
ā āāā main.go
ā āāā migrate
ā āāā main.go
āāā config.toml
āāā go.mod
āāā go.sum
āāā internal
ā āāā config
ā ā āāā app_config.go
ā āāā handlers
ā ā āāā web_handlers.go
ā āāā routes
ā ā āāā routes.go
ā āāā utils
ā āāā render_util.go
āāā resources
āāā css
ā āāā main.css
ā āāā variables.css
āāā images
ā āāā favicon.ico
ā āāā screenshot.png
āāā js
ā āāā components
ā ā āāā ButtonComponent.js
ā ā āāā ...
ā āāā controllers
ā ā āāā ButtonController.js
ā āāā main.js
āāā views
āāā Base.html
āāā layouts
ā āāā FrontLayout.html
āāā pages
āāā Start.html
Contribution
Contributions to this project are welcome! Please follow these guidelines:
- Fork the repository and create a new branch for your contribution.
- Make your changes and ensure that the code is properly formatted.
- Write clear and concise commit messages.
- Test your changes thoroughly.
- Submit a pull request to the main repository.
Thank you for your contribution!
License
This project is licensed under the MIT License - see the LICENSE file for details.