fiber-boilerplate

module
v0.0.0-...-bd5dacb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2024 License: MIT

README

fiber-boilerplate

A simple boilerplate for Fiber

Go Report Card MIT license go.dev reference

Sommaire

Commands list

Command Description
<binary> run Start server
<binary> logs -s Server logs reader
<binary> logs -d Database (GORM) logs reader
<binary> register Create a new user

Makefile commands

Makefile command Go command Description
make update go get -u && go mod tidy Update Go dependencies
make serve go run cmd/main.go Start the Web server
make serve-race go run --race cmd/main.go Start the Web server with data races option
make build go build -o go-url-shortener -v cmd/main.go Build application
make test go test -cover ./... Launch unit tests
make test-verbose go test -cover -v ./... Launch unit tests in verbose mode
make logs go run cmd/main.go logs -s Start server logs reader

Routes

Liste des routes

Swagger

TODO

Golang web server in production

Creating a Service for Systemd
touch /lib/systemd/system/<service name>.service

Edit file:

[Unit]
Description=<service description>
After=network.target

[Service]
Type=simple
Restart=always
RestartSec=5s
ExecStart=<path to exec with arguments>

[Install]
WantedBy=multi-user.target
Commande Description
systemctl start <service name>.service To launch
systemctl enable <service name>.service To enable on boot
systemctl disable <service name>.service To disable on boot
systemctl status <service name>.service To show status
systemctl stop <service name>.service To stop

Benchmark

Use Drill

$ drill --benchmark drill.yml --stats --quiet

Go documentation

Installer godoc (pas dans le répertoire du projet) :

go get -u golang.org/x/tools/...

Puis lancer :

godoc -http=localhost:6060 -play=true -index

Mesure et performance

Go met à disposition de puissants outils pour mesurer les performances des programmes :

  • pprof (graph, flamegraph, peek)
  • trace
  • cover

=> Lien vers une vidéo intéressante Mesure et optimisation de la performance en Go

pprof

Lancer :

curl http://localhost:<port>/debug/pprof/heap?seconds=10 > <fichier à analyser>

Puis :

go tool pprof -http :7000 <fichier à analyser> # Interface web
go tool pprof --nodefraction=0 -http :7000 <fichier à analyser> # Interface web avec tous les noeuds
go tool pprof <fichier à analyser> # Ligne de commande
trace

Lancer :

go test <package path> -trace=<fichier à analyser>
curl localhost:<port>/debug/pprof/trace?seconds=10 > <fichier à analyser>

Puis :

go tool trace <fichier à analyser>
cover

Lancer :

go test <package path> -covermode=count -coverprofile=./<fichier à analyser>

Puis :

go tool cover -html=<fichier à analyser>

Generate JWT ES384 keys

mkdir keys

# Private key
openssl ecparam -name secp384r1 -genkey -noout -out keys/private.ec.key

# Public key
openssl ec -in keys/private.ec.key -pubout -out keys/public.ec.pem

# Convert SEC1 private key to PKCS8
openssl pkcs8 -topk8 -nocrypt -in keys/private.ec.key -out keys/private.ec.pem

rm keys/private.ec.key

TODO

  • Add scope to JWT
  • Attention : Le middleware websocket de Fiber génère une data race avec le hub ! Voir si cela sera corrigé à l'avenir (lever une issue sur Github ?)
  • Add Docker support
    • Try OpenTelemetry middleware
    • Mettre en place la stack Prometheus + Grafana pour la télémétrie
    • Add Prometheus metrics (Example)
    • Create a first user to use API
  • Try test suite ginkgo and gomega

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL