Minimal frontend for administering our LDAP server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

52 lines
1009 B

package main
import (
"encoding/json"
"errors"
"fmt"
"os"
"github.com/spf13/pflag"
)
type config struct {
ListenAddr string `json:"listenAddr"`
Ldap ldapConfig `json:"ldap"`
}
type ldapConfig struct {
URL string `json:"url"`
StartTLS bool `json:"starttls"`
UserFormat string `json:"userformat"`
}
func parseConfig() (config, error) {
configFile := "config.json"
pflag.StringVarP(&configFile, "config", "c", configFile, "Path to configuration file.")
pflag.Parse()
var c config
file, err := os.Open(configFile)
if err != nil {
return c, fmt.Errorf("can not open configuration file: %s", err)
}
if err := json.NewDecoder(file).Decode(&c); err != nil {
return c, fmt.Errorf("can not parse configuration: %s", err)
}
if c.ListenAddr == "" {
c.ListenAddr = ":8080"
}
if c.Ldap.URL == "" {
return c, errors.New("ldap.url can not be empty")
}
if c.Ldap.UserFormat == "" {
return c, errors.New("ldap.userformat can not be empty")
}
return c, nil
}