Categorygithub.com/buelbuel/gowc
repository
0.0.0-20240715063824-abe75281c820
Repository: https://github.com/buelbuel/gowc.git
Documentation: pkg.go.dev

# Packages

No description provided by the author

# README

Web Application Scaffolding with Echo Framework

Go Reference codecov Go Report Card GitHub License

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

  1. Clone the repository:
    git clone https://github.com/buelbuel/gowc.git
    cd gowc
    
  2. Install dependencies:
    go mod download
    go install github.com/air-verse/air@latest
    
  3. Run the application:
    air
    
  4. 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 EnableCorsto 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 to true 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:

  1. Fork the repository and create a new branch for your contribution.
  2. Make your changes and ensure that the code is properly formatted.
  3. Write clear and concise commit messages.
  4. Test your changes thoroughly.
  5. 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.