cadoles-profile/cmd/server/config/config.go
William Petit eba02717cf Modification du mot de passe fonctionnel
- Ajout de jeton anti CSRF dans les formulaires de login/profile
2019-05-22 14:24:53 +02:00

64 lines
1.1 KiB
Go

package config
import (
"io"
ini "gopkg.in/ini.v1"
)
type Config struct {
HTTP HTTPConfig
LDAP LDAPConfig
}
type HTTPConfig struct {
Address string
TemplateDir string
PublicDir string
}
type LDAPConfig struct {
URL string
BaseDN string
UserSearchFilterPattern string
}
// NewFromFile retrieves the configuration from the given file
func NewFromFile(filepath string) (*Config, error) {
config := NewDefault()
cfg, err := ini.Load(filepath)
if err != nil {
return nil, err
}
if err := cfg.MapTo(config); err != nil {
return nil, err
}
return config, nil
}
func NewDefault() *Config {
return &Config{
HTTP: HTTPConfig{
Address: ":3000",
TemplateDir: "./templates",
PublicDir: "./public",
},
LDAP: LDAPConfig{
URL: "ldap://127.0.0.1:389",
BaseDN: "o=org,c=fr",
UserSearchFilterPattern: "(&(objectClass=person)(uid=%s))",
},
}
}
func Dump(config *Config, w io.Writer) error {
cfg := ini.Empty()
if err := cfg.ReflectFrom(config); err != nil {
return err
}
if _, err := cfg.WriteTo(w); err != nil {
return err
}
return nil
}