Initial commit
This commit is contained in:
30
utils/dotenv.go
Normal file
30
utils/dotenv.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
|
||||
func init(){
|
||||
loadEnv()
|
||||
}
|
||||
|
||||
func loadEnv(){
|
||||
log.Print("Loading .env file...")
|
||||
err := godotenv.Load()
|
||||
if err != nil {
|
||||
log.Fatal("error loading .env file")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func Env(name string) string{
|
||||
envVar := os.Getenv(name)
|
||||
if envVar == "" {
|
||||
log.Fatalf("error getting %s env variable", name)
|
||||
}
|
||||
return envVar
|
||||
}
|
||||
29
utils/ldap.go
Normal file
29
utils/ldap.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"gt.kalli.st/czar/fsldap/config"
|
||||
)
|
||||
|
||||
func GetMail(user string) string {
|
||||
return fmt.Sprintf("%s@%s", user, config.Domain)
|
||||
}
|
||||
|
||||
func GetLdapName(user string) string {
|
||||
return fmt.Sprintf("%s=%s,%s", config.Uid, user, config.Base)
|
||||
}
|
||||
|
||||
func GetUser(name string) string {
|
||||
endIndex := len(name) - config.BaseLenght
|
||||
user := name[config.UidLenght:endIndex]
|
||||
return user
|
||||
}
|
||||
|
||||
func GetSearchUser(name string) string {
|
||||
startIndex := config.UidLenght + 1
|
||||
endIndex := len(name) - 1
|
||||
user := name[startIndex:endIndex]
|
||||
return user
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user