* Use gopkg.in/ini.v1 over github.com/joho/godotenv * Fix typos Signed-off-by: Shin'ya Minazuki <shinyoukai@laidback.moe>
50 lines
821 B
Go
50 lines
821 B
Go
package utils
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"git.laidback.moe/YakumoLabs/efsldap/config"
|
|
)
|
|
|
|
var (
|
|
Base = config.Config.LDAPBase
|
|
Domain = config.Config.SMTPDomain
|
|
Uid = config.Config.LDAPUID
|
|
)
|
|
|
|
var (
|
|
BaseLength = len(Base) + 1
|
|
UidLength = len(Uid) + 1
|
|
)
|
|
|
|
func GetMail(user string) string {
|
|
return fmt.Sprintf("%s@%s", user, Domain)
|
|
}
|
|
|
|
func GetLdapName(user string) string {
|
|
return fmt.Sprintf("%s=%s,%s", Uid, user, Base)
|
|
}
|
|
|
|
func GetUser(name string) string {
|
|
endIndex := len(name) - BaseLength
|
|
if endIndex < 0 {
|
|
return ""
|
|
}
|
|
user := name[UidLength:endIndex]
|
|
|
|
user = strings.TrimSuffix(user, "@"+Domain)
|
|
|
|
return user
|
|
}
|
|
|
|
func GetSearchUser(name string) string {
|
|
startIndex := UidLength + 1
|
|
endIndex := len(name) - 1
|
|
if endIndex < 0 {
|
|
return ""
|
|
}
|
|
user := name[startIndex:endIndex]
|
|
return user
|
|
}
|
|
|