mirror of
https://github.com/mindoc-org/mindoc.git
synced 2025-12-21 11:13:57 +08:00
搭建框架
This commit is contained in:
30
utils/gob.go
Normal file
30
utils/gob.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/gob"
|
||||
)
|
||||
|
||||
//解码
|
||||
func Decode(value string,r interface{}) (error) {
|
||||
|
||||
network := bytes.NewBuffer([]byte(value));
|
||||
|
||||
dec := gob.NewDecoder(network)
|
||||
|
||||
return dec.Decode(r);
|
||||
}
|
||||
|
||||
//编码
|
||||
func Encode(value interface{}) (string,error) {
|
||||
network:= bytes.NewBuffer(nil);
|
||||
|
||||
enc := gob.NewEncoder(network)
|
||||
|
||||
err := enc.Encode(value);
|
||||
if err != nil {
|
||||
return "",err;
|
||||
}
|
||||
|
||||
return network.String(),nil;
|
||||
}
|
||||
Reference in New Issue
Block a user