Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
张磊
/
FileStorageBeego
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
237aaadd
authored
2014-05-17 00:43:51 +0800
by
astaxie
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
session:support struct.
gob.Register(v)
1 parent
34ddcef1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
0 deletions
session/sess_test.go
session/sess_utils.go
session/sess_test.go
View file @
237aaad
...
...
@@ -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 @
237aaad
...
...
@@ -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
Styling with
Markdown
is supported
Attach a file
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 post a comment