server

package module
v0.0.0-...-db79cbe Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2022 License: MIT Imports: 23 Imported by: 0

README

go-url-shortener

A simple URL shortener written in Go with Fiber

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

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 install golang.org/x/tools/...@latest

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>

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitLogger

func InitLogger() (*zap.Logger, error)

InitLogger initializes custom Zap logger configuration.

func Run

func Run(db *db.DB, logger *zap.Logger)

Run starts HTTP server

Types

This section is empty.

Directories

Path Synopsis
server module

Jump to

Keyboard shortcuts

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