func (r *Record) CopyHead() Head {
	return Head{
		Datfile: r.Datfile,
		Stamp:   r.Stamp,
		ID:      r.ID,
	}
}
CopyHead copies and  returns Head.
package record
import (
	"bytes"
	"errors"
	"fmt"
	"log"
	"regexp"
	"strconv"
	"strings"
	"encoding/json"
	"github.com/boltdb/bolt"
	"github.com/shingetsu-gou/shingetsu-gou/cfg"
	"github.com/shingetsu-gou/shingetsu-gou/db"
	"github.com/shingetsu-gou/shingetsu-gou/node"
	"github.com/shingetsu-gou/shingetsu-gou/util"
)
var cachedRule *util.RegexpList
type DB struct {
	*Head
	Body    string
	Deleted bool
}
func (d *DB) Del(tx *bolt.Tx) {
	if err := db.Del(tx, "record", d.Head.ToKey()); err != nil {
		log.Println(err)
	}
}
func (d *DB) Put(tx *bolt.Tx) error {
	return db.Put(tx, "record", d.Head.ToKey(), d)
}
func GetFromDB(tx *bolt.Tx, h *Head) (*DB, error) {
	d := DB{}
	_, err := db.Get(tx, "record", h.ToKey(), &d)
	return &d, err
}
func GetFromDBs(tx *bolt.Tx, datfile string) ([]*DB, error) {
	var cnt []*DB
	bdatfile := make([]byte, len(datfile)+1)
	copy(bdatfile, datfile)
	bdatfile[len(datfile)] = 0x0
	b := tx.Bucket([]byte("record"))
	if b == nil {
		return nil, errors.New("bucket not found record")
	}
	c := b.Cursor()
	for k, v := c.Seek(bdatfile); bytes.HasPrefix(k, bdatfile); k, v = c.Next() {
		str := DB{}
		if err := json.Unmarshal(v, &str); err != nil {
			return nil, err
		}
		cnt = append(cnt, &str)
	}
	return cnt, nil
}
func ForEach(tx *bolt.Tx, eachDo func(*DB) error) error {
	b := tx.Bucket([]byte("record"))
	if b == nil {
		return errors.New("bucket not found record")
	}
	c := b.Cursor()
	d := DB{}
	for k, v := c.First(); k != nil; k, v = c.Next() {
		if errr := json.Unmarshal(v, &d); errr != nil {
			return errr
		}
		if errr := eachDo(&d); errr != nil {
			return errr
		}
	}
	return nil
}
type Record struct {
	*Head
	contents map[string]string
	keyOrder []string
}
func NewIDstr(datfile, idstr string) (*Record, error) {
	if idstr == "" {
		return New(datfile, "", 0), nil
	}
	buf := strings.Split(idstr, "_")
	if len(buf) != 2 {
		err := errors.New("bad format")
		log.Println(idstr, ":bad format")
		return nil, err
	}
	var stamp int64
	var err error
	if stamp, err = strconv.ParseInt(buf[0], 10, 64); err != nil {
		log.Println(idstr, ":bad format")
		return nil, err
	}
	return New(datfile, buf[1], stamp), nil
}
func New(datfile, id string, stamp int64) *Record {
	return &Record{
		Head: &Head{
			Datfile: datfile,
			Stamp:   stamp,
			ID:      id,
		},
	}
}