Beispiel #1
0
// Generate generates AccessToken.
func Generate(seed []byte) AccessToken {
	id := uuid.NewUUID()
	for i := 0; i < 1000; i++ {
		sha := uuid.NewSHA1(id, seed)
		md5 := uuid.NewMD5(id, seed)
		seed = append(sha, md5...)
	}
	encoded := base58.Encode(seed)
	return New(encoded[:40])
}
Beispiel #2
0
func vcardify(emp Employee, org, prefix, suffix string) string {
	var buf bytes.Buffer

	buf.WriteString("BEGIN:VCARD\n")
	buf.WriteString("VERSION:3.0\n")
	buf.WriteString(fmt.Sprintf(
		"REV:%s\n", time.Now().UTC().Format("2006-01-02T15:04:05Z")))

	buf.WriteString("PRODID:-//Topface//yml2vcard//EN\n")

	names := strings.Split(emp.Name, " ")
	var firstname, lastname string
	switch len(names) {
	case 1:
		firstname, lastname = names[0], ""
	case 2:
		firstname, lastname = names[0], names[1]
	case 3:
		firstname, lastname = names[0], names[2]
	default:
		firstname, lastname = emp.Name, ""
	}

	buf.WriteString(fmt.Sprintf(
		"N:%s;%s;;%s;%s\n", lastname, firstname, prefix, suffix))

	buf.WriteString("FN:")
	if prefix != "" {
		buf.WriteString(prefix + " ")
	}
	buf.WriteString(emp.Name)
	if suffix != "" {
		buf.WriteString(" " + suffix)
	}
	buf.WriteString("\n")

	if org != "" {
		buf.WriteString("ORG:")
		buf.WriteString(org)
		buf.WriteString("\n")
	}

	if emp.Phone != "" {
		buf.WriteString(fmt.Sprintf(
			"TEL:%s\n", emp.Phone))
	}

	if len(emp.ExtraPhones) > 0 {
		for _, p := range emp.ExtraPhones {
			buf.WriteString(fmt.Sprintf(
				"TEL:%s\n", p))
		}
	}

	if emp.WorkMail != "" {
		buf.WriteString(fmt.Sprintf(
			"EMAIL;TYPE=work:%s\n", emp.WorkMail))
	}

	if emp.PersonalMail != "" {
		buf.WriteString(fmt.Sprintf(
			"EMAIL;TYPE=home:%s\n", emp.PersonalMail))
	}

	if len(emp.ExtraMails) > 0 {
		for _, m := range emp.ExtraMails {
			buf.WriteString(fmt.Sprintf(
				"EMAIL:%s\n", m))
		}
	}

	uuid := uuid.NewMD5(uuid.NIL, []byte(emp.Name))
	buf.WriteString(fmt.Sprintf(
		"X-RADICALE-NAME:%s.vcf\n", uuid.String()))
	buf.WriteString(fmt.Sprintf(
		"UID:%s\n", uuid.String()))

	buf.WriteString("END:VCARD\n")

	return buf.String()
}