guichet/http-utils.go

41 lines
931 B
Go
Raw Normal View History

2023-07-21 04:37:18 +00:00
/*
http-utils provide utility functions that interact with http
*/
package main
import (
"crypto/tls"
2023-07-21 12:15:44 +00:00
"net"
2023-07-21 04:37:18 +00:00
"net/http"
"github.com/go-ldap/ldap/v3"
)
func logRequest(handler http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
2023-07-21 14:40:28 +00:00
// log.Printf("%s %s %s\n", r.RemoteAddr, r.Method, r.URL)
2023-07-21 04:37:18 +00:00
handler.ServeHTTP(w, r)
})
}
2023-07-21 12:15:44 +00:00
func ldapOpen(w http.ResponseWriter) (*ldap.Conn, error) {
2023-07-21 04:37:18 +00:00
if config.LdapTLS {
2023-07-21 12:15:44 +00:00
tlsConf := &tls.Config{
ServerName: config.LdapServerAddr,
InsecureSkipVerify: true,
2023-07-21 04:37:18 +00:00
}
2023-07-21 12:15:44 +00:00
return ldap.DialTLS("tcp", net.JoinHostPort(config.LdapServerAddr, "636"), tlsConf)
} else {
return ldap.DialURL("ldap://" + config.LdapServerAddr)
2023-07-21 04:37:18 +00:00
}
2023-07-21 12:15:44 +00:00
// if err != nil {
// http.Error(w, err.Error(), http.StatusInternalServerError)
// log.Printf(fmt.Sprintf("27: %v %v", err, l))
// return nil
// }
// return l
2023-07-21 04:37:18 +00:00
}