Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cogolabs/go-boilerplate
Go boilerplate web server with all Cogo specific best practices
https://github.com/cogolabs/go-boilerplate
boilerplate golang handler metrics prometheus router
Last synced: 2 months ago
JSON representation
Go boilerplate web server with all Cogo specific best practices
- Host: GitHub
- URL: https://github.com/cogolabs/go-boilerplate
- Owner: cogolabs
- Created: 2018-08-31T19:55:10.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2022-04-15T17:50:12.000Z (almost 3 years ago)
- Last Synced: 2024-06-20T10:08:11.785Z (8 months ago)
- Topics: boilerplate, golang, handler, metrics, prometheus, router
- Language: Go
- Homepage:
- Size: 1.72 MB
- Stars: 28
- Watchers: 1
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Table of Contents
- [Overview](#overview)
- [cmd](#cmd)
- [pkg](#pkg)
- [internal](#internal)
- [metrics and pprof](#metrics-and-pprof)
- [web](#web)
- [testing](#testing)
- [Github Actions](#github-actions)# Overview
Go boilerplate is a simple web server starter pack with Cogo's best practices. These are standard across all projects to ensure easy interoperability, understandability, and discoverability.
To get started, we recommend reading [Go By Example](https://gobyexample.com/), then, after getting more comfortable with the language, [Effective Go](https://go.dev/doc/effective_go). You should also be familiar with [Go Modules](https://go.dev/blog/using-go-modules).
# cmd
The `cmd` directory holds entrypoints into your application. Each binary that gets built and run gets their own directory and `main.go` inside the `cmd` directory.
# pkg
The `pkg` directory holds the majority of your source code. Anything that you will need to access from inside and your repository or other packages lives here.
# internal
The `internal` directory holds your source code that must never be imported by other go modules. The go compiler does not allow imports from `internal` packages that are outside your module.
# metrics and pprof
We use Prometheus for our application metrics, see `pkg/metrics/metrics.go`. You'll need to set up a prometheus scraper to ingest these metrics.
[pprof](https://jvns.ca/blog/2017/09/24/profiling-go-with-pprof/) lets you collect useful data on the state of a running go program.
# web
For its rich functionality, we use `github.com/gorilla/mux` for handling HTTP requests.
# testing
Tests are written in files named `*_test.go` and can be run with the `go test` tool.
All golang test functions must start with `Test` in their names, in order for them to be visible to the go tester. Each test should accept the first argument `(t* Testing.t)`, which will most likely be the only argument you need. We use [stretchr/testify](https://github.com/stretchr/testify) as our assertion library to ensure correctness.
# Github Actions
We use Github Actions to compile and test our code on every push. Depending on the project, we may also use it for continuous delivery. The yaml in `.github/workflows/` defines how the code should be built and how the tests should be run.