Ejemplo n.º 1
0
// Convert the domain system object to a limited information user format. We have a persisted flag
// to known when the object exists in our database or not to choose when we need to add the object
// links or not
func ToDomainResponse(domain model.Domain, persisted bool) DomainResponse {
	var links []Link

	// We don't add links when the object doesn't exist in the system yet
	if persisted {
		// We should add more links here for system navigation. For example, we could add links
		// for object update, delete, list, etc. But I did not found yet in IANA list the
		// correct link type to be used. Also, the URI is hard coded, I didn't have any idea on
		// how can we do this dynamically yet. We cannot get the URI from the handler because we
		// are going to have a cross-reference problem
		links = append(links, Link{
			Types: []LinkType{LinkTypeSelf},
			HRef:  fmt.Sprintf("/domain/%s", domain.FQDN),
		})
	}

	// We will try to show the FQDN always in unicode format. To solve a little bug in IDN library, we
	// will always convert the FQDN to lower case
	fqdn := strings.ToLower(domain.FQDN)

	var err error
	fqdn, err = idna.ToUnicode(fqdn)
	if err != nil {
		// On error, keep the ace format
		fqdn = strings.ToLower(domain.FQDN)
	}

	return DomainResponse{
		FQDN:        fqdn,
		Nameservers: toNameserversResponse(domain.Nameservers),
		DSSet:       toDSSetResponse(domain.DSSet),
		Owners:      toOwnersResponse(domain.Owners),
		Links:       links,
	}
}
Ejemplo n.º 2
0
// fqdnToUnicode converts a FQDN from ACE format to unicode
func fqdnToUnicode(fqdn string) string {
	unicode, err := idna.ToUnicode(fqdn)
	if err != nil {
		// if it's an invalid ace format, just return the FQDN
		return fqdn
	}
	return unicode
}