diff --git a/config.go b/config.go index e1d405c..0f62a74 100644 --- a/config.go +++ b/config.go @@ -18,6 +18,8 @@ type Config struct { Ldap *LdapConfig Secret string Tls bool + Key string + Cert string Port string } @@ -41,6 +43,8 @@ func LoadConfig() (*Config, error) { c := &Config{} l := &LdapConfig{} viper.SetDefault("port", "8080") + viper.SetDefault("secret", "") + viper.SetDefault("Tls", false) //Load configs l.Url = viper.GetString("ldapUrl") l.AdminUser = viper.GetString("adminUser") @@ -50,6 +54,8 @@ func LoadConfig() (*Config, error) { c.Secret = viper.GetString("secret") c.Tls = viper.GetBool("tls") c.Port = viper.GetString("port") + c.Key = viper.GetString("tls_key") + c.Cert = viper.GetString("tls_cert") //Validate configs if validateConfigEntry(l.Url, "ldapUrl") || validateConfigEntry(l.AdminUser, "adminUser") || validateConfigEntry(l.UserOu, "userOu") || validateConfigEntry(l.LdapDc, "ldapDc") || validateConfigEntry(l.UserAttr, "userAttr") { diff --git a/main.go b/main.go index e61f7e4..3b1422f 100644 --- a/main.go +++ b/main.go @@ -45,6 +45,9 @@ func main() { http.HandleFunc("/register", signupPage) http.HandleFunc("/", homePage) log.Printf("Guildgate starting on %v\n", Conf.Port) - http.ListenAndServe(":"+Conf.Port, nil) - + if Conf.Tls { + http.ListenAndServeTLS(":"+Conf.Port, Conf.Cert, Conf.Key, nil) + } else { + http.ListenAndServe(":"+Conf.Port, nil) + } }