diff --git a/README.md b/README.md index 6bec8a0..571352c 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ $ ALTCHA_HMAC_KEY="CLÉ HMAC" bin/altcha verify [CHALLENGE] [SALT] [SIGNATURE] [ ## Variables d'environement | Nom | Description | Valeur par défaut | Requis | |---------------------|------------------------------------------------------------------------------|--------------------------|--------| +| ALTCHA_HOST | Adresse de l'hôte | localhost | Non | | ALTCHA_PORT | Port d'écoute du serveur | 3333 | Non | | ALTCHA_HMAC_KEY | Clé d'encodage des signatures | | Oui | | ALTCHA_MAX_NUMBER | Nombre d'itération maximum pour résoudre le challenge (défini la difficulté) | 1000000 | Non | diff --git a/internal/api/server.go b/internal/api/server.go index 6057a65..f97b51d 100644 --- a/internal/api/server.go +++ b/internal/api/server.go @@ -17,10 +17,21 @@ import ( ) type Server struct { + host string port string client client.Client } +func NewServer(cfg config.Config) *Server { + client := *client.NewClient(cfg.HmacKey, cfg.MaxNumber, cfg.Algorithm, cfg.Salt, cfg.Expire, cfg.CheckExpire) + + return &Server { + host: cfg.Host, + port: cfg.Port, + client: client, + } +} + func (s *Server) Run(ctx context.Context) { r := chi.NewRouter() @@ -37,7 +48,7 @@ func (s *Server) Run(ctx context.Context) { r.Get("/verify-spam-filter", s.submitSpamFilterHandler) logger.Info(ctx, "altcha server listening on port "+s.port) - if err := http.ListenAndServe(":"+s.port, r); err != nil { + if err := http.ListenAndServe(s.host+":"+s.port, r); err != nil { logger.Error(ctx, err.Error()) } } @@ -166,12 +177,3 @@ func formToMap(r *http.Request) (map[string][]string, error) { return r.Form, nil } - -func NewServer(cfg config.Config) *Server { - client := *client.NewClient(cfg.HmacKey, cfg.MaxNumber, cfg.Algorithm, cfg.Salt, cfg.Expire, cfg.CheckExpire) - - return &Server { - port: cfg.Port, - client: client, - } -} \ No newline at end of file diff --git a/internal/config/config.go b/internal/config/config.go index 3f33206..979e927 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -1,6 +1,7 @@ package config type Config struct { + Host string `env:"ALTCHA_HOST" envDefault:"localhost"` Port string `env:"ALTCHA_PORT" envDefault:"3333"` HmacKey string `env:"ALTCHA_HMAC_KEY"` MaxNumber int64 `env:"ALTCHA_MAX_NUMBER" envDefault:"1000000"`