-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnjson.go
executable file
·47 lines (38 loc) · 1.15 KB
/
njson.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package campid
import (
"github.com/influx6/npkg"
"github.com/influx6/npkg/nerror"
)
type JSONSession struct {
*Zone
}
// EncodeForCookie encodes giving session to npkg.ObjectEncoder for
// delivery to the client.
func (s *JSONSession) EncodeForCookie(encoder npkg.ObjectEncoder) error {
if err := s.Validate(); err != nil {
return nerror.WrapOnly(err)
}
encoder.String("id", s.Id)
encoder.String("method", s.Method)
encoder.String("user", s.UserId)
encoder.Int64("created", s.Created.Unix())
encoder.Int64("updated", s.Updated.Unix())
if s.Meta != nil && len(s.Meta) != 0 {
encoder.Object("meta", npkg.EncodableStringMap(s.Meta))
}
return encoder.Err()
}
// EncodeObject implements the npkg.EncodableObject interface.
func (s *JSONSession) EncodeObject(encoder npkg.ObjectEncoder) error {
if err := s.Validate(); err != nil {
return nerror.WrapOnly(err)
}
encoder.String("id", s.Id)
encoder.String("method", s.Method)
encoder.String("method", s.Method)
encoder.String("user", s.UserId)
encoder.Int64("created", s.Created.Unix())
encoder.Int64("updated", s.Updated.Unix())
encoder.Object("meta", npkg.EncodableStringMap(s.Meta))
return nil
}