From dfc26b821cd428edff171a2d2cc2e1be8eef404e Mon Sep 17 00:00:00 2001 From: yo Date: Fri, 29 Sep 2023 11:35:58 +0200 Subject: [PATCH] v0.5.7 : Ajout flag -version, correction filtre cn= --- main.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index b63e5e1..1a93537 100644 --- a/main.go +++ b/main.go @@ -22,7 +22,7 @@ import ( ) var ( - gVersion = "0.5.6" + gVersion = "0.5.8" gRoLdap *MyLdap ) @@ -263,6 +263,7 @@ func initRouter(r *gin.Engine) { c.AbortWithError(http.StatusInternalServerError, nil) return } + defer ldapCon.Conn.Close() // json format is the default format := c.DefaultQuery("format", "json") @@ -298,6 +299,7 @@ func initRouter(r *gin.Engine) { c.AbortWithError(http.StatusInternalServerError, nil) return } + defer ldapCon.Conn.Close() modified, err := checkIfModifiedSince(c, ldapCon, ou, cn, class, "ALL") if err != nil { @@ -334,6 +336,7 @@ func initRouter(r *gin.Engine) { c.AbortWithError(http.StatusInternalServerError, nil) return } + defer ldapCon.Conn.Close() res, err := searchByCn(ldapCon, ou, cn, class, attr) if err != nil { @@ -365,6 +368,7 @@ func initRouter(r *gin.Engine) { c.AbortWithError(http.StatusInternalServerError, nil) return } + defer ldapCon.Conn.Close() modified, err := checkIfModifiedSince(c, ldapCon, ou, cn, class, attr) if err != nil { @@ -405,6 +409,7 @@ func initRouter(r *gin.Engine) { c.AbortWithError(http.StatusInternalServerError, err) return } + defer ldapCon.Conn.Close() // Unmarshall json body to a map if c.Request.Header.Get("Content-Type") == "application/json" { @@ -468,6 +473,7 @@ func initRouter(r *gin.Engine) { c.AbortWithError(http.StatusInternalServerError, err) return } + defer ldapCon.Conn.Close() // Unmarshall json body to a map if c.Request.Header.Get("Content-Type") == "application/json" { @@ -521,6 +527,7 @@ func initRouter(r *gin.Engine) { c.AbortWithError(http.StatusInternalServerError, err) return } + defer ldapCon.Conn.Close() // Unmarshall json body to a map if c.Request.Header.Get("Content-Type") == "application/json" { @@ -570,6 +577,7 @@ func main() { var tlsCert string var doTls bool var debug bool + var showversion bool flag.StringVar(&confFile, "config", "", "Path to the config file (optional)") flag.StringVar(&listen, "listen-addr", "0.0.0.0:8080", "listen address for server") @@ -582,9 +590,15 @@ func main() { flag.StringVar(&tlsPrivKey, "ssl-private-key", "", "SSL Private key") flag.StringVar(&tlsCert, "ssl-certificate", "", "SSL certificate (PEM format)") flag.BoolVar(&debug, "debug", false, "Set log level to debug") + flag.BoolVar(&showversion, "version", false, "Show version then exit") flag.Parse() + if showversion { + fmt.Printf("GlApi v%s\n", gVersion) + return + } + if len(confFile) > 0 { viper.SetConfigFile(confFile) if err := viper.ReadInConfig(); err != nil {