Пример #1
0
// Read record header data.
func runGetHeaderExample(client *as.Client) {
	key, _ := as.NewKey(*shared.Namespace, *shared.Set, "putgetkey")

	log.Printf("Get record header: namespace=%s set=%s key=%s", key.Namespace(), key.SetName(), key.Value())
	record, err := client.GetHeader(shared.Policy, key)
	shared.PanicOnError(err)

	if record == nil {
		panic(errors.New(fmt.Sprintf(
			"Failed to get: namespace=%s set=%s key=%s", key.Namespace(), key.SetName(), key.Value())))
	}

	// Generation should be greater than zero.  Make sure it's populated.
	if record.Generation == 0 {
		panic(errors.New(fmt.Sprintf(
			"Invalid record header: generation=%d expiration=%d", record.Generation, record.Expiration)))
	}
	log.Printf("Received: generation=%d expiration=%d (%s)\n", record.Generation, record.Expiration, time.Duration(record.Expiration)*time.Second)
}