pk.go 426 B

1234567891011121314151617181920212223242526
  1. package core
  2. import (
  3. "bytes"
  4. "encoding/gob"
  5. )
  6. type PK []interface{}
  7. func NewPK(pks ...interface{}) *PK {
  8. p := PK(pks)
  9. return &p
  10. }
  11. func (p *PK) ToString() (string, error) {
  12. buf := new(bytes.Buffer)
  13. enc := gob.NewEncoder(buf)
  14. err := enc.Encode(*p)
  15. return buf.String(), err
  16. }
  17. func (p *PK) FromString(content string) error {
  18. dec := gob.NewDecoder(bytes.NewBufferString(content))
  19. err := dec.Decode(p)
  20. return err
  21. }