コード例 #1
0
ファイル: domain.go プロジェクト: rafaeljusto/shelter
// 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,
	}
}
コード例 #2
0
ファイル: templates.go プロジェクト: rafaeljusto/shelter
// 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
}