This repository has been archived on 2024-03-03. You can view files and clone it, but cannot push or open issues or pull requests.
adlin/libadlin/domain.go

61 lines
1.6 KiB
Go

package adlin
import (
"fmt"
"strings"
)
var (
AssociatedDomainSuffixes = []string{"adlin2023.driivve.com.", "adlin2023.driivve.co.", "adlin2023.driivee.cloud.", "adlin2023.p0m.fr."}
DelegatedDomainSuffixes = []string{"srs.driivve.com.", "srs.driivve.co.", "srs.driivee.cloud.", "srs.p0m.fr."}
)
func (student *Student) MyDelegatedDomainSuffix() string {
if student.DelegatedDomain != nil {
for _, ddomain := range DelegatedDomainSuffixes {
if strings.HasSuffix(*student.DelegatedDomain, ddomain) {
return ddomain
}
}
}
return DelegatedDomainSuffixes[int(student.Id)%len(DelegatedDomainSuffixes)]
}
func (student *Student) MyDelegatedDomain() string {
if student.DelegatedDomain != nil {
return *student.DelegatedDomain
}
return fmt.Sprintf("%s.%s", strings.Trim(strings.Replace(student.Login, "_", "-", -1), "-_"), student.MyDelegatedDomainSuffix())
}
func (student *Student) MyAssociatedDomainSuffix() string {
return AssociatedDomainSuffixes[int(student.Id)%len(AssociatedDomainSuffixes)]
}
func (student *Student) DefaultAssociatedDomain() string {
return fmt.Sprintf("%s.%s", strings.Trim(strings.Replace(student.Login, "_", "-", -1), "-_"), student.MyAssociatedDomainSuffix())
}
func (student *Student) MyAssociatedDomain() string {
if student.AssociatedDomain != nil {
return *student.AssociatedDomain
}
return student.DefaultAssociatedDomain()
}
func (student *Student) GetAssociatedDomains() (ds []string) {
defdn := student.DefaultAssociatedDomain()
ds = append(ds, defdn)
studentDomain := student.MyAssociatedDomain()
if defdn != studentDomain {
ds = append(ds, studentDomain)
}
return
}