Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
c2657862
Commit
c2657862
authored
May 16, 2014
by
astaxie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
session:support struct.
gob.Register(v)
parent
c5c806b5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
0 deletions
+12
-0
sess_test.go
session/sess_test.go
+9
-0
sess_utils.go
session/sess_utils.go
+3
-0
No files found.
session/sess_test.go
View file @
c2657862
...
...
@@ -16,6 +16,7 @@ func Test_gob(t *testing.T) {
a
:=
make
(
map
[
interface
{}]
interface
{})
a
[
"username"
]
=
"astaxie"
a
[
12
]
=
234
a
[
"user"
]
=
User
{
"asta"
,
"xie"
}
b
,
err
:=
EncodeGob
(
a
)
if
err
!=
nil
{
t
.
Error
(
err
)
...
...
@@ -33,6 +34,14 @@ func Test_gob(t *testing.T) {
if
c
[
12
]
!=
234
{
t
.
Error
(
"decode int error"
)
}
if
c
[
"user"
]
.
(
User
)
.
Username
!=
"asta"
{
t
.
Error
(
"decode struct error"
)
}
}
type
User
struct
{
Username
string
NickName
string
}
func
TestGenerate
(
t
*
testing
.
T
)
{
...
...
session/sess_utils.go
View file @
c2657862
...
...
@@ -34,6 +34,9 @@ func init() {
}
func
EncodeGob
(
obj
map
[
interface
{}]
interface
{})
([]
byte
,
error
)
{
for
_
,
v
:=
range
obj
{
gob
.
Register
(
v
)
}
buf
:=
bytes
.
NewBuffer
(
nil
)
enc
:=
gob
.
NewEncoder
(
buf
)
err
:=
enc
.
Encode
(
obj
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment