pk.go 588 B

123456789101112131415161718192021222324252627282930
  1. // Copyright 2019 The Xorm Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package core
  5. import (
  6. "bytes"
  7. "encoding/gob"
  8. )
  9. type PK []interface{}
  10. func NewPK(pks ...interface{}) *PK {
  11. p := PK(pks)
  12. return &p
  13. }
  14. func (p *PK) ToString() (string, error) {
  15. buf := new(bytes.Buffer)
  16. enc := gob.NewEncoder(buf)
  17. err := enc.Encode(*p)
  18. return buf.String(), err
  19. }
  20. func (p *PK) FromString(content string) error {
  21. dec := gob.NewDecoder(bytes.NewBufferString(content))
  22. err := dec.Decode(p)
  23. return err
  24. }