refactor readme updated
This commit is contained in:
parent
c4b1d1c2ba
commit
8562fc6553
5 changed files with 57 additions and 24 deletions
45
README.md
45
README.md
|
|
@ -1,6 +1,6 @@
|
||||||
# Essence
|
# Prix du gaz
|
||||||
|
|
||||||
Carte de chaleur des prix d'essence au Québec affichant les prix en temps réel des stations à travers la province.
|
Carte des prix d'essence au Québec affichant les prix en temps réel des stations à travers la province.
|
||||||
|
|
||||||
## Fonctionnalités
|
## Fonctionnalités
|
||||||
|
|
||||||
|
|
@ -28,7 +28,7 @@ direnv allow
|
||||||
go run .
|
go run .
|
||||||
|
|
||||||
# Ou avec des paramètres personnalisés
|
# Ou avec des paramètres personnalisés
|
||||||
PORT=8080 ESSENCE_DB=./essence.db go run .
|
PORT=8080 PRIXDUGAZ_DB=./prixdugaz.db go run .
|
||||||
```
|
```
|
||||||
|
|
||||||
Le serveur démarre à `http://localhost:8080` et redirige `/` vers `/map`.
|
Le serveur démarre à `http://localhost:8080` et redirige `/` vers `/map`.
|
||||||
|
|
@ -49,19 +49,19 @@ Le serveur démarre à `http://localhost:8080` et redirige `/` vers `/map`.
|
||||||
| Variable | Défaut | Description |
|
| Variable | Défaut | Description |
|
||||||
|----------|--------|-------------|
|
|----------|--------|-------------|
|
||||||
| `PORT` | `8080` | Port d'écoute HTTP |
|
| `PORT` | `8080` | Port d'écoute HTTP |
|
||||||
| `ESSENCE_DB` | `./essence.db` | Chemin de la base de données SQLite |
|
| `PRIXDUGAZ_DB` | `./prixdugaz.db` | Chemin de la base de données SQLite |
|
||||||
|
|
||||||
## Compilation
|
## Compilation
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
go build -o essence .
|
go build -o prixdugaz .
|
||||||
```
|
```
|
||||||
|
|
||||||
Ou via Nix :
|
Ou via Nix :
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
nix build
|
nix build
|
||||||
./result/bin/essence
|
./result/bin/prixdugaz
|
||||||
```
|
```
|
||||||
|
|
||||||
## Formatage et analyse statique
|
## Formatage et analyse statique
|
||||||
|
|
@ -72,6 +72,39 @@ goimports -w .
|
||||||
go vet ./...
|
go vet ./...
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Déploiement sur NixOS
|
||||||
|
|
||||||
|
Le projet fournit un module NixOS via le flake. Ajoutez-le à votre configuration :
|
||||||
|
|
||||||
|
**1. Ajoutez le flake comme entrée (`flake.nix`) :**
|
||||||
|
|
||||||
|
```nix
|
||||||
|
inputs.prixdugaz.url = "github:Polensky/prixdugaz";
|
||||||
|
```
|
||||||
|
|
||||||
|
**2. Importez le module NixOS et activez le service :**
|
||||||
|
|
||||||
|
```nix
|
||||||
|
imports = [ inputs.prixdugaz.nixosModules.default ];
|
||||||
|
|
||||||
|
services.prixdugaz = {
|
||||||
|
enable = true;
|
||||||
|
port = 8080; # optionnel, 8080 par défaut
|
||||||
|
openFirewall = true; # optionnel, ouvre le port dans le pare-feu
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
**Options disponibles :**
|
||||||
|
|
||||||
|
| Option | Défaut | Description |
|
||||||
|
|--------|--------|-------------|
|
||||||
|
| `enable` | `false` | Active le service |
|
||||||
|
| `port` | `8080` | Port d'écoute HTTP |
|
||||||
|
| `dataDir` | `/var/lib/prixdugaz` | Répertoire de la base de données SQLite |
|
||||||
|
| `openFirewall` | `false` | Ouvre le port dans le pare-feu |
|
||||||
|
| `package` | flake par défaut | Paquet Prix du gaz à utiliser |
|
||||||
|
|
||||||
|
|
||||||
## Licence
|
## Licence
|
||||||
|
|
||||||
MIT
|
MIT
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
description = "Essence Quebec - Gas price heatmap";
|
description = "Prix du gaz Quebec - Gas price heatmap";
|
||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
packages.default = pkgs.buildGoModule {
|
packages.default = pkgs.buildGoModule {
|
||||||
pname = "essence";
|
pname = "prixdugaz";
|
||||||
version = "0.1.0";
|
version = "0.1.0";
|
||||||
src = ./.;
|
src = ./.;
|
||||||
vendorHash = "sha256-iiobqg0INKuzTyC/VMGcX5CfroqqbKnwlJLVAOCZbEE=";
|
vendorHash = "sha256-iiobqg0INKuzTyC/VMGcX5CfroqqbKnwlJLVAOCZbEE=";
|
||||||
|
|
|
||||||
2
go.mod
2
go.mod
|
|
@ -1,4 +1,4 @@
|
||||||
module github.com/polen/essence
|
module github.com/polen/prixdugaz
|
||||||
|
|
||||||
go 1.25.0
|
go 1.25.0
|
||||||
|
|
||||||
|
|
|
||||||
6
main.go
6
main.go
|
|
@ -107,9 +107,9 @@ func main() {
|
||||||
port = defaultPort
|
port = defaultPort
|
||||||
}
|
}
|
||||||
|
|
||||||
dbPath := os.Getenv("ESSENCE_DB")
|
dbPath := os.Getenv("PRIXDUGAZ_DB")
|
||||||
if dbPath == "" {
|
if dbPath == "" {
|
||||||
dbPath = "./essence.db"
|
dbPath = "./prixdugaz.db"
|
||||||
}
|
}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|
@ -983,7 +983,7 @@ func fetchAndParse() (*StationsResponse, error) {
|
||||||
return nil, fmt.Errorf("creating request: %w", err)
|
return nil, fmt.Errorf("creating request: %w", err)
|
||||||
}
|
}
|
||||||
req.Header.Set("Accept-Encoding", "gzip")
|
req.Header.Set("Accept-Encoding", "gzip")
|
||||||
req.Header.Set("User-Agent", "essence-quebec-map/1.0")
|
req.Header.Set("User-Agent", "prixdugaz-quebec-map/1.0")
|
||||||
|
|
||||||
client := &http.Client{Timeout: 30 * time.Second}
|
client := &http.Client{Timeout: 30 * time.Second}
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
|
|
|
||||||
|
|
@ -2,48 +2,48 @@
|
||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
let
|
let
|
||||||
cfg = config.services.essence;
|
cfg = config.services.prixdugaz;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.services.essence = {
|
options.services.prixdugaz = {
|
||||||
enable = lib.mkEnableOption "Essence Quebec gas price map";
|
enable = lib.mkEnableOption "Prix du gaz Quebec gas price map";
|
||||||
|
|
||||||
port = lib.mkOption {
|
port = lib.mkOption {
|
||||||
type = lib.types.port;
|
type = lib.types.port;
|
||||||
default = 8080;
|
default = 8080;
|
||||||
description = "Port the Essence web server listens on.";
|
description = "Port the Prix du gaz web server listens on.";
|
||||||
};
|
};
|
||||||
|
|
||||||
dataDir = lib.mkOption {
|
dataDir = lib.mkOption {
|
||||||
type = lib.types.str;
|
type = lib.types.str;
|
||||||
default = "/var/lib/essence";
|
default = "/var/lib/prixdugaz";
|
||||||
description = "Directory where the SQLite database is stored.";
|
description = "Directory where the SQLite database is stored.";
|
||||||
};
|
};
|
||||||
|
|
||||||
openFirewall = lib.mkOption {
|
openFirewall = lib.mkOption {
|
||||||
type = lib.types.bool;
|
type = lib.types.bool;
|
||||||
default = false;
|
default = false;
|
||||||
description = "Whether to open the firewall for the Essence web server port.";
|
description = "Whether to open the firewall for the Prix du gaz web server port.";
|
||||||
};
|
};
|
||||||
|
|
||||||
package = lib.mkOption {
|
package = lib.mkOption {
|
||||||
type = lib.types.package;
|
type = lib.types.package;
|
||||||
default = self.packages.${pkgs.system}.default;
|
default = self.packages.${pkgs.system}.default;
|
||||||
defaultText = lib.literalExpression "self.packages.\${pkgs.system}.default";
|
defaultText = lib.literalExpression "self.packages.\${pkgs.system}.default";
|
||||||
description = "The Essence package to use.";
|
description = "The Prix du gaz package to use.";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = lib.mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
systemd.services.essence = {
|
systemd.services.prixdugaz = {
|
||||||
description = "Essence Quebec - Gas price map";
|
description = "Prix du gaz Quebec - Gas price map";
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
after = [ "network-online.target" ];
|
after = [ "network-online.target" ];
|
||||||
wants = [ "network-online.target" ];
|
wants = [ "network-online.target" ];
|
||||||
|
|
||||||
environment = {
|
environment = {
|
||||||
PORT = toString cfg.port;
|
PORT = toString cfg.port;
|
||||||
ESSENCE_DB = "${cfg.dataDir}/essence.db";
|
PRIXDUGAZ_DB = "${cfg.dataDir}/prixdugaz.db";
|
||||||
};
|
};
|
||||||
|
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
|
|
@ -52,7 +52,7 @@ in
|
||||||
RestartSec = 5;
|
RestartSec = 5;
|
||||||
|
|
||||||
DynamicUser = true;
|
DynamicUser = true;
|
||||||
StateDirectory = "essence";
|
StateDirectory = "prixdugaz";
|
||||||
StateDirectoryMode = "0750";
|
StateDirectoryMode = "0750";
|
||||||
|
|
||||||
# Hardening
|
# Hardening
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue