update
This commit is contained in:
parent
75a1bf1576
commit
c33b59bcab
3 changed files with 12 additions and 12 deletions
|
@ -2,17 +2,17 @@ package securecookie
|
|||
|
||||
import "fmt"
|
||||
|
||||
var _ Codec = (*UnsafeCodec)(nil)
|
||||
var _ Codec = (*LiteCodec)(nil)
|
||||
|
||||
func NewUnsafeCodec() *UnsafeCodec {
|
||||
s := &UnsafeCodec{
|
||||
func NewLiteCodec() *LiteCodec {
|
||||
s := &LiteCodec{
|
||||
sz: GobEncoder{},
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// UnsafeCodec encodes and decodes
|
||||
type UnsafeCodec struct {
|
||||
// LiteCodec encodes and decodes
|
||||
type LiteCodec struct {
|
||||
err error
|
||||
sz Serializer
|
||||
}
|
||||
|
@ -21,14 +21,14 @@ type UnsafeCodec struct {
|
|||
//
|
||||
// Default is encoding/gob. To encode special structures using encoding/gob,
|
||||
// they must be registered first using gob.Register().
|
||||
func (s *UnsafeCodec) SetSerializer(sz Serializer) *UnsafeCodec {
|
||||
func (s *LiteCodec) SetSerializer(sz Serializer) *LiteCodec {
|
||||
s.sz = sz
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
// Encode encodes a value.
|
||||
func (s *UnsafeCodec) Encode(name string, value interface{}) (string, error) {
|
||||
func (s *LiteCodec) Encode(name string, value interface{}) (string, error) {
|
||||
if s.err != nil {
|
||||
return "", s.err
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ func (s *UnsafeCodec) Encode(name string, value interface{}) (string, error) {
|
|||
}
|
||||
|
||||
// Decode decodes a value. The dst argument must be a pointer.
|
||||
func (s *UnsafeCodec) Decode(name, value string, dst interface{}, _ ...int) error {
|
||||
func (s *LiteCodec) Decode(name, value string, dst interface{}, _ ...int) error {
|
||||
if s.err != nil {
|
||||
return s.err
|
||||
}
|
|
@ -2,9 +2,9 @@ package securecookie
|
|||
|
||||
import "testing"
|
||||
|
||||
func TestUnsafeCodec(t *testing.T) {
|
||||
c := NewUnsafeCodec()
|
||||
str := `TestUnsafeCodec`
|
||||
func TestLiteCodec(t *testing.T) {
|
||||
c := NewLiteCodec()
|
||||
str := `TestLiteCodec`
|
||||
encoded, err := c.Encode(`name`, str)
|
||||
if err != nil {
|
||||
t.Error(err)
|
|
@ -49,7 +49,7 @@ func SetSerializer(codecs []Codec, sz Serializer) {
|
|||
for _, c := range codecs {
|
||||
if codec, ok := c.(*SecureCookie); ok {
|
||||
codec.SetSerializer(sz)
|
||||
} else if codec, ok := c.(*UnsafeCodec); ok {
|
||||
} else if codec, ok := c.(*LiteCodec); ok {
|
||||
codec.SetSerializer(sz)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue