Added login, some auth methods and a couple routes with no implementation

This commit is contained in:
Miguel de la Cruz 2021-09-13 10:06:57 +02:00
parent f76aa74179
commit f1cae0d660
79 changed files with 8971 additions and 10 deletions

View file

@ -14,12 +14,17 @@ const (
type Config struct {
DatabasePath *string `yaml:"database_path"`
Port *int `yaml:"port"`
Secret *string `yaml:"secret"`
}
func (c *Config) SetDefaults() {
if c.Port == nil {
c.Port = NewInt(DefaultPort)
}
if c.Secret == nil {
c.Secret = NewString(NewUUID())
}
}
func (c *Config) IsValid() error {
@ -31,6 +36,10 @@ func (c *Config) IsValid() error {
return fmt.Errorf("port cannot be empty")
}
if c.Secret == nil || *c.Secret == "" {
return fmt.Errorf("secret cannot be empty")
}
return nil
}
@ -45,5 +54,7 @@ func ReadConfig(path string) (*Config, error) {
return nil, err
}
config.SetDefaults()
return &config, nil
}

View file

@ -7,6 +7,6 @@ import (
func NewString(s string) *string { return &s }
func NewInt(i int) *int { return &i }
func NewID() string {
func NewUUID() string {
return uuid.New().String()
}