Skip to content

This project provides a boilerplate for building RESTful APIs using Go. It is designed to a quick start with best practices, easy configuration, and a clear project structure.

License

Notifications You must be signed in to change notification settings

H0llyW00dzZ/My-RESTAPIs-Boilerplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

My RESTful API Boilerplate

Golang logo
Image Copyright Β© SAWARATSUKI. All rights reserved.
Image used under permission from the copyright holder.

This project provides a boilerplate for building RESTful APIs using Go. It is designed to a quick start with best practices, easy configuration, and a clear project structure.

Warning

This boilerplate is specifically tailored for extensive codebases and scalable RESTful API applications, along with frontend websites that may span multiple sites. Its design ensures scalability and straightforward maintenance, making it highly suitable for complex projects. However, it may not be the ideal choice for smaller-scale RESTful API applications or single-website frontends where such robust architecture is not required.

Tip

Given that this boilerplate focuses on high performance (e.g., it can handle substantial workloads), it is recommended to run and isolate it on Kubernetes. It has been tested alongside the worker package and has proven to be fully stable for low to high workloads (concurrency). Running and isolating it on Kubernetes allows for easy scaling when additional resources, such as vCPUs, are needed.

Features

  • Use Fiber Framework
  • Pre-configured MySQL and Redis integration
  • Middleware examples for logging and authentication
  • Scalable project structure
  • Dual-licensed under BSD 3-Clause and MIT (specific files)
  • High Performance (Thanks to the Sonic JSON serializing & deserializing library)
  • Cryptography Techniques
  • High Quality Go Codes
  • Rich Presence TUIs using charm.sh
  • Boring TLS 1.3 Protocol (WIP) -> EOL (No longer actively developed due to time constraints)
  • Certificate Transparency (CT) Log -> EOL (No longer actively developed due to time constraints)

Note

Boring TLS 1.3 Protocol This project utilizes the industry-standard TLS 1.3 protocol, known for its exceptional security and reliability. We call it Boring TLS because its robust security makes it almost boring.

Note

Certificate Transparency (CT) Log This project includes built-in support for submitting certificates to Certificate Transparency logs. It supports certificates with both RSA and ECDSA keys. By submitting certificates to CT logs, it enhances the security and transparency of the TLS ecosystem, allowing domain owners to monitor and detect fraudulent certificates or other bad certificates. The CT log functionality is implemented using the SubmitToCTLog function, which takes the certificate, private key, and CT log details as input. It encodes the certificate, calculates the hash, creates a JSON payload, sends an HTTP request to the CT log server, and verifies the signed certificate timestamp (SCT) received in the response. The VerifySCT method is responsible for verifying the SCT based on the public key type (RSA or ECDSA) and ensures the integrity of the timestamp. With this feature, it is easy to integrate certificate transparency into the TLS setup and contribute to a more secure web.

Warning

Some features might not work as expected when running this repo on certain cloud providers. For example, the Rich Presence TUIs feature requires a tty. The reason why some features might not work as expected after implementation is because this repo is designed to be top-level and follow the Unix philosophy. Plus, most of the Go code in this repo follows many best practices and idioms from Effective Go.

Tip

Due to the large codebase of this repository, which includes many sub-packages such as helper functions (lazy splitting into another repository), consider implementing your own or an alternative main Go mechanism (follow best practices here). This can be used across multiple containers in a single deployment for infrastructure purposes. Personally, I have created many such mechanisms for running in Kubernetes (k8s) based on this starter repository.

TODO Features

Move here

Note

Additional features will be added later as my primary focus is on using this with the Fiber framework and Cryptography Techniques.

Supported Additional Features

Note

The following list includes additional features that I've been using before for extremely scalable and high-performance applications:

Motivation

The motivation for sharing this RESTful API Boilerplate on GitHub is to streamline my development process, ensuring I don't have to start from scratch each time. It's a robust, secure foundation that adheres to best practices, designed for quick and efficient project initiation.

Philosophy

This boilerplate is grounded in the Unix philosophy, emphasizing simplicity, modularity, and reusability. Each component is designed to do one thing and do it well, with the ability to combine components seamlessly to perform complex tasks. This approach ensures that the boilerplate remains lightweight, efficient, and easy to maintain.

Gopher Drink

Resource Memory Usage

  • MySQL without Redis 100K POST Request (Outdated - go1.22.2)

Memory Usage with MYSQL

Note

The Resource Memory Usage section demonstrates how Go has stable and low memory overhead compared to other languages, especially Java (See this article for more information on Java memory management Lmao.) hahaha.

  • Idle (Outdated - go1.22.2)

Idle

Note

The Idle section demonstrates the memory usage when there is no request. The maximum average memory usage is around 21.5MB. Go routines (100 goroutines) along with a semaphore are used to automatically handle high traffic situations (e.g., lots of requests).

Also Note that even with high incoming traffic (e.g., 1 million requests), the maximum average memory usage is still relatively low, around 100MB (e.g., 50MB), due to the use of the semaphore.

Latest

  • Idle (Outdated - go1.22.3)

Idle-go1.22.3

sample#memory_total=8.01MB
sample#memory_rss=7.92MB
sample#memory_cache=0.09MB
sample#memory_swap=0.00MB
sample#memory_pgpgin=0pages
sample#memory_pgpgout=0pages
sample#memory_quota=1024.00MB

Note

Go Memory Usage Improvements:

  • The Idle memory usage in the latest version of Go has been optimized, reducing it to approximately 7.92MB compared to the previous version.

Average Memory Usage Breakdown:

  • The average memory usage of 11.1MB includes:
    • Go routine scheduler for database operations (separate from the 100 goroutines used for handling high incoming traffic automatically with a semaphore)
    • Load for the front-end website
    • Load for the REST APIs (Full Stack)
  • The application remains stable without any performance issues, such as bottlenecks or memory leaks, and has zero vulnerabilities.

Go Performance Comparison:

  • Compared to other languages, particularly for full-stack development, Go demonstrates superior performance.

gopher run

TLS 1.3 Connection Stable

  • Standard TLS 1.3 (Latest Go Version - go1.22.5)

tls-go1.22.5

tls-go1.22.5

tls-go1.22.5-cracked-zer0ms-response

tls-go1.22.5-cracked-zer0ms-response

Note

The screenshots provided demonstrate a Standard TLS 1.3 connection using the Closed networks or intranets method, which involves Cloudflare (Frontend) and Heroku (Backend). Without Cloudflare, any browser or tools like curl won't be able to access the backend server.

Frontend Performance

  • Error Page (Include Wildcard Handler)

error-page

Note

The screenshot provided demonstrates the performance of an Error Page, and it can easily be optimized to achieve all green metrics.

Tip

Also note that when optimized to achieve all green metrics which is easily, especially in the SEO category, it can be beneficial for business logic purposes. (e.g, Search engines like Google and Microsoft Bing tend to favor websites with good performance metrics, which can lead to improved search rankings and increased visibility.)

Prometheus

  • Latest Go Version

prometheus-portable

prometheus-portable

prometheus-portable

prometheus-portable

Note

The grafana dashboard is not shareable due to it being bound to my security configurations for real-world monitoring in other production environments.

Architecture (Tree)

Below is the architecture of this boilerplate and how it looks. I created this for REST APIs about volcano πŸŒ‹ monitoring used by the government (has been done before), so it can easily monitor volcanoes in the real world.

  • Backend (Pure Go)
backend/
|-- cmd/
|   `-- server/ (main application entry point)
|       `-- main.go
|-- pkg/
|   |-- restapis/ (API route handlers)
|   |-- any/ (any related code)
|-- internal/ (private application and library code)
|   |-- any/ (any related code)
|-- .env (optional environment variables since it can placed anywhere)
`-- go.mod (dependencies)
  • Frontend (Any Framework TS e.g, React,NextJS or pure JS for HTMX)

Example:

frontend/
|-- pages/
|   |-- api/ (optional, for Next.js API routes if needed)
|   |-- _app.js (global page layouts and state)
|   |-- index.js (home page)
|   `-- [...other pages]
|-- public/ (static files like images, fonts)
|-- src/
|   |-- components/ (shared React components)
|   |   `-- [various components]
|   |-- styles/ (global styles, theme)
|   |-- hooks/ (custom React hooks)
|   |-- utils/ (utility functions)
|   |-- lib/ (libraries and configurations)
|   `-- context/ (React context files for state management)
|-- .env.local (environment variables)
|-- next.config.js (Next.js configuration)
`-- package.json (dependencies and scripts)

Current Boilerplate Tree:

β”œβ”€β”€ Dockerfile
β”œβ”€β”€ LICENSE
β”œβ”€β”€ README.md
β”œβ”€β”€ SECURITY.md
β”œβ”€β”€ backend
β”‚Β Β  β”œβ”€β”€ cmd
β”‚Β Β  β”‚Β Β  └── server
β”‚Β Β  β”‚Β Β      β”œβ”€β”€ run.go
β”‚Β Β  β”‚Β Β      β”œβ”€β”€ run_heroku.go
β”‚Β Β  β”‚Β Β      β”œβ”€β”€ run_immutable.go
β”‚Β Β  β”‚Β Β      └── run_tls_fips.go
β”‚Β Β  β”œβ”€β”€ internal
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ database
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ auth.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ backup.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ cloudflare-kv
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  └── setup.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ constant.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ helper.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ mysql_redis.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ redis_json.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ setup.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ sql_injection_test.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  └── tls.go
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ logger
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ constant.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  └── logger.go
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ middleware
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ authentication
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ crypto
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ bcrypt
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ bcrypt.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ bcrypt_test.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ compare_password.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ docs.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  └── hash_password.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ cipher.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ crypto.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ crypto_test.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ deadcode.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ decrypt.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ encrypt.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ gopherpocket
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  └── keyrotation
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ docs.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ gopherkey.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      └── gopherkey_test.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ gpg
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ benchmark_test.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ config.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ docs.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ encrypt.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ encrypt_test.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ file.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ key_info.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ key_ring.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ keybox.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ keybox_test.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  └── new.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ helper.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ hybrid
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ decryptcookie.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ encryptcookie.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ hybrid.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ hybrid_stream.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ hybrid_test.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  └── stream
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ benchmark_test.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ chunk.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ decrypt_stream.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ digest.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ docs.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ encrypt_stream.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ new_stream.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ nonce.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      └── stream_test.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ keyidentifier
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ docs.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ ecdsa_sign.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ generate.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ keyidentifier_test.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  └── new.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ rand
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ benchmark_test.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ fixed_size.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ rand_test.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  └── uuid.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ tls
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ docs.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  └── setup.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ vault
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ new.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  └── transit.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ web3
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  └── eth
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ docs.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      └── new.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  └── webauthn
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ docs.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ login.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ protocol.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      └── registration.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ helper
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ constant.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  └── keyauth.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  └── keyauth
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ constant.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ error.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ success.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      └── validator.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ constant.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ csp
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ config.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ csp_test.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  └── new.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ custom_logger_tag.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ custom_next.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ filesystem
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  └── crypto
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      └── signature
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β          β”œβ”€β”€ hmac_sign.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β          β”œβ”€β”€ hmac_test.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β          └── hmac_verify.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ frontend_routes.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ helper.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ init.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ lb_test.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ monitor
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ docs.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  └── prometheus.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ restapis_routes.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ restime
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ config.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  └── new.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ router
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  └── domain
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ config.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      └── new.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ routes.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ routes_immutable.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ routes_non_immutable.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ storage.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  └── utils.go
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ server
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ boringtls.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ boringtls_cert.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ boringtls_cert_test.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ boringtls_test.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ constant.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ ct_verifier.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ ct_verifier_test.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ helper.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ helper_tls_test.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ k8s
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ docs.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  └── metrics
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      └── prometheus.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ mount_routes.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ register_routes.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  └── startup_async.go
β”‚Β Β  β”‚Β Β  └── translate
β”‚Β Β  β”‚Β Β      └── language.go
β”‚Β Β  └── pkg
β”‚Β Β      β”œβ”€β”€ gc
β”‚Β Β      β”‚Β Β  β”œβ”€β”€ docs.go
β”‚Β Β      β”‚Β Β  β”œβ”€β”€ reduce_http_client_overhead.go
β”‚Β Β      β”‚Β Β  β”œβ”€β”€ reduce_overhead.go
β”‚Β Β      β”‚Β Β  └── unique.go
β”‚Β Β      β”œβ”€β”€ header
β”‚Β Β      β”‚Β Β  └── htmx
β”‚Β Β      β”‚Β Β      β”œβ”€β”€ constant.go
β”‚Β Β      β”‚Β Β      └── docs.go
β”‚Β Β      β”œβ”€β”€ mime
β”‚Β Β      β”‚Β Β  β”œβ”€β”€ ascii.go
β”‚Β Β      β”‚Β Β  β”œβ”€β”€ docs.go
β”‚Β Β      β”‚Β Β  └── mime.go
β”‚Β Β      └── restapis
β”‚Β Β          β”œβ”€β”€ helper
β”‚Β Β          β”‚Β Β  β”œβ”€β”€ auth
β”‚Β Β          β”‚Β Β  β”‚Β Β  β”œβ”€β”€ apikey.go
β”‚Β Β          β”‚Β Β  β”‚Β Β  └── constant.go
β”‚Β Β          β”‚Β Β  β”œβ”€β”€ generate_apikey.go
β”‚Β Β          β”‚Β Β  β”œβ”€β”€ generate_apikey_test.go
β”‚Β Β          β”‚Β Β  β”œβ”€β”€ json
β”‚Β Β          β”‚Β Β  β”‚Β Β  └── sonic
β”‚Β Β          β”‚Β Β  β”‚Β Β      β”œβ”€β”€ config.go
β”‚Β Β          β”‚Β Β  β”‚Β Β      └── docs.go
β”‚Β Β          β”‚Β Β  β”œβ”€β”€ numeric.go
β”‚Β Β          β”‚Β Β  β”œβ”€β”€ numeric_test.go
β”‚Β Β          β”‚Β Β  β”œβ”€β”€ restapis_error.go
β”‚Β Β          β”‚Β Β  └── restapis_error_test.go
β”‚Β Β          └── server
β”‚Β Β              └── health
β”‚Β Β                  β”œβ”€β”€ cache.go
β”‚Β Β                  β”œβ”€β”€ constant.go
β”‚Β Β                  β”œβ”€β”€ db.go
β”‚Β Β                  β”œβ”€β”€ helper.go
β”‚Β Β                  β”œβ”€β”€ mysql.go
β”‚Β Β                  └── redis.go
β”œβ”€β”€ env
β”‚Β Β  β”œβ”€β”€ docs.go
β”‚Β Β  β”œβ”€β”€ env.go
β”‚Β Β  └── getenv.go
β”œβ”€β”€ frontend
β”‚Β Β  β”œβ”€β”€ htmx
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ error_page_handler
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ 400.templ
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ 400_templ.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ 401.templ
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ 401_templ.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ 403.templ
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ 403_templ.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ 404.templ
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ 404_templ.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ 500.templ
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ 500_templ.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ 503.templ
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ 503_templ.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ base.templ
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ base_templ.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ page_handler.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ render_frontend.go
β”‚Β Β  β”‚Β Β  β”‚Β Β  └── static_handler.go
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ public
β”‚Β Β  β”‚Β Β  β”‚Β Β  └── assets
β”‚Β Β  β”‚Β Β  β”‚Β Β      └── css
β”‚Β Β  β”‚Β Β  β”‚Β Β          └── base-tailwind.css
β”‚Β Β  β”‚Β Β  └── site
β”‚Β Β  β”‚Β Β      β”œβ”€β”€ footer.templ
β”‚Β Β  β”‚Β Β      β”œβ”€β”€ footer_templ.go
β”‚Β Β  β”‚Β Β      β”œβ”€β”€ head.templ
β”‚Β Β  β”‚Β Β      β”œβ”€β”€ head_templ.go
β”‚Β Β  β”‚Β Β      β”œβ”€β”€ header.templ
β”‚Β Β  β”‚Β Β      β”œβ”€β”€ header_templ.go
β”‚Β Β  β”‚Β Β      β”œβ”€β”€ script.templ
β”‚Β Β  β”‚Β Β      └── script_templ.go
β”‚Β Β  └── public
β”‚Β Β      β”œβ”€β”€ assets
β”‚Β Β      β”‚Β Β  β”œβ”€β”€ css
β”‚Β Β      β”‚Β Β  β”‚Β Β  β”œβ”€β”€ base-tailwind.css
β”‚Β Β      β”‚Β Β  β”‚Β Β  └── raw.css
β”‚Β Β      β”‚Β Β  β”œβ”€β”€ images
β”‚Β Β      β”‚Β Β  β”‚Β Β  β”œβ”€β”€ android-chrome-192x192.png
β”‚Β Β      β”‚Β Β  β”‚Β Β  β”œβ”€β”€ android-chrome-512x512.png
β”‚Β Β      β”‚Β Β  β”‚Β Β  β”œβ”€β”€ apple-touch-icon.png
β”‚Β Β      β”‚Β Β  β”‚Β Β  β”œβ”€β”€ browserconfig.xml
β”‚Β Β      β”‚Β Β  β”‚Β Β  β”œβ”€β”€ favicon-16x16.png
β”‚Β Β      β”‚Β Β  β”‚Β Β  β”œβ”€β”€ favicon-32x32.png
β”‚Β Β      β”‚Β Β  β”‚Β Β  β”œβ”€β”€ favicon.ico
β”‚Β Β      β”‚Β Β  β”‚Β Β  β”œβ”€β”€ http_error_codes
β”‚Β Β      β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ 403-Forbidden.png
β”‚Β Β      β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ 404-NotFound.png
β”‚Β Β      β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ 500-InternalServerError.png
β”‚Β Β      β”‚Β Β  β”‚Β Β  β”‚Β Β  └── 503-ServiceUnavailable.png
β”‚Β Β      β”‚Β Β  β”‚Β Β  β”œβ”€β”€ logo
β”‚Β Β      β”‚Β Β  β”‚Β Β  β”‚Β Β  └── gopher-run.png
β”‚Β Β      β”‚Β Β  β”‚Β Β  β”œβ”€β”€ mstile-150x150.png
β”‚Β Β      β”‚Β Β  β”‚Β Β  β”œβ”€β”€ safari-pinned-tab.svg
β”‚Β Β      β”‚Β Β  β”‚Β Β  └── site.webmanifest
β”‚Β Β      β”‚Β Β  └── js
β”‚Β Β      β”‚Β Β      β”œβ”€β”€ htmx.indicator.min.js
β”‚Β Β      β”‚Β Β      β”œβ”€β”€ htmx.min.js
β”‚Β Β      β”‚Β Β      └── tailwind.min.dark.js
β”‚Β Β      └── magic_embedded.go
β”œβ”€β”€ gcloud-builds.yaml
β”œβ”€β”€ go.mod
β”œβ”€β”€ go.sum
β”œβ”€β”€ k8s-deployment
β”‚Β Β  β”œβ”€β”€ MySQL.md
β”‚Β Β  β”œβ”€β”€ README.md
β”‚Β Β  β”œβ”€β”€ REDIS.md
β”‚Β Β  β”œβ”€β”€ RESTAPIs.md
β”‚Β Β  β”œβ”€β”€ component
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ coredns
β”‚Β Β  β”‚Β Β  β”‚Β Β  └── coredns-hpa.yaml
β”‚Β Β  β”‚Β Β  └── secrets
β”‚Β Β  β”‚Β Β      └── create_k8s_secret.sh
β”‚Β Β  β”œβ”€β”€ mysql-deploy-cpu-boost.yaml
β”‚Β Β  β”œβ”€β”€ mysql-deploy.yaml
β”‚Β Β  β”œβ”€β”€ mysql-storage-eks.yaml
β”‚Β Β  β”œβ”€β”€ mysql-storage-gke.yaml
β”‚Β Β  β”œβ”€β”€ prometheus_portable.yaml
β”‚Β Β  β”œβ”€β”€ prometheus_portable_rules_record.yaml
β”‚Β Β  β”œβ”€β”€ redis-insight.yaml
β”‚Β Β  β”œβ”€β”€ restapis-deploy.yaml
β”‚Β Β  β”œβ”€β”€ restapis-ingress.yaml
β”‚Β Β  └── traffic
β”‚Β Β      └── nginx
β”‚Β Β          β”œβ”€β”€ ingress-nginx-configmap.yaml
β”‚Β Β          β”œβ”€β”€ ingress-nginx-hpa.yaml
β”‚Β Β          β”œβ”€β”€ ingress-nginx-priority.yaml
β”‚Β Β          └── ingress-nginx-vpa.yaml
β”œβ”€β”€ tailwind.config.js
β”œβ”€β”€ translate.json
└── worker
    β”œβ”€β”€ config.go
    β”œβ”€β”€ do_work.go
    β”œβ”€β”€ docs.go
    β”œβ”€β”€ jobs.go
    β”œβ”€β”€ token_bucket.go
    └── worker_test.go

72 directories, 230 files

Note

The Current Boilerplate Tree is designed as a modular framework, and it is easily maintainable even if it reaches 1K files. Personally, I've been maintaining over 1k files as well from this boilerplate, and it runs smoothly on Kubernetes (K8s) β›΅ ☸.

Git Mirror (Auto Synced)

Server Location: Singapore (Stable and very low latency for Southeast Asian Regions, ranging from 10ms ~ 50ms)

πŸ’» >_ Shell:

git clone https://git.b0zal.io/H0llyW00dzZ/My-RESTAPIs-Boilerplate.git

Note

fully-managed-and-isolated-by-k8s

Server Management and Isolation by Kubernetes:

  • The Storage is secure and fully encrypted (end-to-end), designed with flexibility in mind. It is suitable for automated attach/detach processes within a cluster.
  • The Network utilizes a network load balancer controlled by Ingress Nginx, optimizing latency for the APAC region, ensuring smooth sailing β›΅ ☸.
  • The Git SSH should function properly as it utilizes the TCP Service Nginx. It is fully secured, making it resistant to brute-force attacks and exploits due to its underlying logic, which incorporates Elliptic Curve Cryptography (ECC).

Tip

For those in Indonesia, if you are unable to clone repositories (e.g., using git clone) from the Git Mirror (Auto Synced), try using a VPN. This issue may be related to the new load balancer, which could be blocked (by internet provider) or filtered by my firewall mechanism.

It is also more faster with the new load balancer, even when using a VPN (e.g., VPN in Singapore, Indonesia, Malaysia, and other APAC regions), and this improvement applies to both mobile devices and desktops, which incorporate Elliptic Curve Cryptography (ECC) for HTTPS/TLS.

Supported Architectures

Due to the use of Sonic JSON for encoding/decoding, this boilerplate supports only the following architectures:

  • AMD64
  • ARM64

Note

It can also be ideal for multi-architecture workloads.

License

This project is dual-licensed under the BSD 3-Clause License and the MIT License - see the LICENSE file for details.

About

This project provides a boilerplate for building RESTful APIs using Go. It is designed to a quick start with best practices, easy configuration, and a clear project structure.

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Languages