Ajout de la configuration du host
This commit is contained in:
parent
ca1d3810a8
commit
63adbd06ea
|
@ -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 |
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
|
@ -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"`
|
||||
|
|
Loading…
Reference in New Issue