本文整理汇总了Golang中encoding/gob.Register函数的典型用法代码示例。如果您正苦于以下问题:Golang Register函数的具体用法?Golang Register怎么用?Golang Register使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Register函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: NewWithClock
// NewWithClock creates a new coordinate.Coordinate connection object,
// using an explicit time source. See New() for further details.
// Most application code should call New(), and use the default (real)
// time source; this entry point is intended for tests that need to
// inject a mock time source.
func NewWithClock(connectionString string, clk clock.Clock) (coordinate.Coordinate, error) {
// If the connection string is a destructured URL, turn it
// back into a proper URL
if len(connectionString) >= 2 && connectionString[0] == '/' && connectionString[1] == '/' {
connectionString = "postgres:" + connectionString
}
db, err := sql.Open("postgres", connectionString)
if err != nil {
return nil, err
}
// TODO(dmaze): shouldn't unconditionally do this force-upgrade here
err = Upgrade(db)
if err != nil {
return nil, err
}
// Make sure the gob library understands our data maps
gob.Register(map[string]interface{}{})
gob.Register(map[interface{}]interface{}{})
gob.Register([]interface{}{})
gob.Register(cborrpc.PythonTuple{})
gob.Register(uuid.UUID{})
return &pgCoordinate{
db: db,
clock: clk,
}, nil
}
开发者ID:dmaze,项目名称:goordinate,代码行数:32,代码来源:coordinate.go
示例2: dumpTrace
func dumpTrace(args []string) {
dumpTraceFlagset.Parse(args)
if _dumpTraceFlags.TracePath == "" {
fmt.Printf("specify path of trace data file\n")
os.Exit(1)
}
file, err := os.Open(_dumpTraceFlags.TracePath)
if err != nil {
fmt.Printf("failed to open trace data file(%s): %s\n", _dumpTraceFlags.TracePath, err)
os.Exit(1)
}
gob.Register(map[string]interface{}{})
gob.Register([]map[string]interface{}{})
dec := gob.NewDecoder(file)
var trace SingleTrace
derr := dec.Decode(&trace)
if derr != nil {
fmt.Printf("failed to decode trace file(%s): %s\n", _dumpTraceFlags.TracePath, err)
os.Exit(1)
}
doDumpTrace(&trace)
}
开发者ID:philips,项目名称:earthquake,代码行数:25,代码来源:dump_trace.go
示例3: init
//init registers the necessary models to be saved in the session later
func init() {
gob.Register(&models.User{})
gob.Register(&models.Flash{})
Store.Options.HttpOnly = true
// This sets the maxAge to 5 days for all cookies
Store.MaxAge(86400 * 5)
}
开发者ID:thansau239,项目名称:gophish,代码行数:8,代码来源:auth.go
示例4: init
func init() {
datastore.Register(NewType())
// Need to register types that will be used to fulfill interfaces.
gob.Register(&Type{})
gob.Register(&Data{})
}
开发者ID:tartavull,项目名称:dvid,代码行数:7,代码来源:googlevoxels.go
示例5: init
func init() {
registerHandlers("vm", vmCLIHandlers)
// for vm info
gob.Register(VMs{})
gob.Register(&vmKVM{})
}
开发者ID:summits,项目名称:minimega,代码行数:7,代码来源:vm_cli.go
示例6: TestActorClient
func TestActorClient(t *testing.T) {
config.Config.UseAuth = true
indexer.Initialize(config.Config)
c, _ := client.New("fooclient")
gob.Register(c)
c.Save()
c1, err := GetReqUser("fooclient")
if err != nil {
t.Errorf(err.Error())
}
y := c1.IsSelf(c)
if y == false {
t.Errorf("self not equal to self")
}
c2, _ := client.New("foo2client")
y = c1.IsSelf(c2)
if y != false {
t.Errorf("client %s was equal to client %s, but should not have been", c1.GetName(), c2.Name)
}
u, _ := user.New("foouser")
gob.Register(u)
u.Save()
y = c1.IsSelf(u)
if y != false {
t.Errorf("client %s was equal to user %s, but should not have been", c1.GetName(), u.Username)
}
c.Delete()
c2.Delete()
u.Delete()
}
开发者ID:theckman,项目名称:goiardi,代码行数:33,代码来源:actor_test.go
示例7: init
func init() {
gob.Register(Car{})
gob.Register(Attribute{})
cacheStorageRedis_test.SetValues(GetRegs(qtdChaves)...)
}
开发者ID:darciopacifico,项目名称:enablecache,代码行数:7,代码来源:serialization_test.go
示例8: startServer
func (c *Client) startServer(socket string) {
rpcs := rpc.NewServer()
rpcs.Register(c)
gob.Register([]interface{}{})
gob.Register(map[string]interface{}{})
if c.options.socktype == "unix" {
os.Remove(socket)
}
if c.options.socktype == "tcp" {
sepIndex := strings.Index(socket, ":")
port := socket[sepIndex:]
socket = "0.0.0.0" + port
}
l, e := net.Listen(c.options.socktype, socket)
if e != nil {
log.Fatal("listen error: ", e)
}
c.l = l
for !c.dead {
conn, err := c.l.Accept()
if err != nil {
fmt.Printf("RPC Error: %v\n", err.Error())
c.l.Close()
} else if !c.dead {
go rpcs.ServeConn(conn)
} else {
return
}
}
}
开发者ID:alect,项目名称:TaskSprint,代码行数:32,代码来源:client.go
示例9: init
func init() {
gob.Register(&filesystem.RegularInode{})
gob.Register(&filesystem.ComputedRegularInode{})
gob.Register(&filesystem.SymlinkInode{})
gob.Register(&filesystem.SpecialInode{})
gob.Register(&filesystem.DirectoryInode{})
}
开发者ID:keep94,项目名称:Dominator,代码行数:7,代码来源:gob.go
示例10: init
func init() {
registerHandlers("vm", vmCLIHandlers)
// Register these so we can serialize the VMs
gob.Register(VMs{})
gob.Register(&KvmVM{})
}
开发者ID:npe9,项目名称:minimega,代码行数:7,代码来源:vm_cli.go
示例11: TestBasic
func TestBasic(t *testing.T) {
Delete()
pdb := Make()
point := Data{1, 2, "hello"}
gob.Register(Data{})
gob.Register("ok")
vals := []interface{}{"A", int(21), int64(22), true, point}
for i, val := range vals {
pdb.Put("paxos", i, "blah", val)
}
// Amazingly, go doesn't let you write a for loop for this. Amazing.
val := ""
true_val := "A"
ok := pdb.Get("paxos", 0, "blah", &val)
chk(t, ok, val, true_val)
// XX A couple missing assertions(Blame go.)
val4 := Data{}
true_val4 := point
ok = pdb.Get("paxos", 4, "blah", &val4)
chk(t, ok, val4, true_val4)
if pdb.Get("paxos", -1, "blah", Data{}) != false {
t.Fatalf("Expected key to not be found!")
}
fmt.Println("Passed!")
Delete()
}
开发者ID:jeffchan,项目名称:pushydb,代码行数:27,代码来源:test_test.go
示例12: netInit
func netInit() {
gob.Register(message{})
gob.Register(node{})
gob.Register(make(map[string]node))
gob.Register(exec.Error{})
gob.Register(errors.New(""))
}
开发者ID:alytvynov,项目名称:lachesis,代码行数:7,代码来源:net.go
示例13: init
func init() {
// For Gob to be able to deal with interfaces, we must
// teach it the concrete types that implement these
// interfaces.
gob.Register(absoluteDirection{0})
gob.Register(relativeDirection{0})
}
开发者ID:Niriel,项目名称:daggor,代码行数:7,代码来源:coords.go
示例14: New
func New(rnConfig RaftNodeConfig, jsonFile string) RaftNode {
var rn RaftNode
rn.eventCh = make(chan interface{}, 100)
//rn.timeoutCh = make(chan bool)
rn.shutdownSig = make(chan bool)
rn.commitCh = make(chan CommitInfo, 100)
// rn.parTOs = 0
rn.logDir = rnConfig.logDir
rn.initializeStateMachine(rnConfig)
var err error
rn.nwHandler, err = cluster.New(int(rnConfig.id), jsonFile)
assert(err == nil)
// Register various types to be send on outbox and receive in inbox
gob.Register(VoteReqEv{})
gob.Register(VoteResEv{})
gob.Register(AppendEntriesReqEv{})
gob.Register(AppendEntriesResEv{})
// Set initial election timeout
/*go func() {
time.Sleep(time.Millisecond * time.Duration(RandInt(rn.sm.electionTO)))
rn.timeoutCh <- true
}()*/
rn.timer = time.NewTimer(time.Duration(RandInt(rnConfig.electionTO)) * time.Millisecond)
return rn
}
开发者ID:salmanpatel,项目名称:cs733,代码行数:30,代码来源:raft_node.go
示例15: init
func init() {
log.SetFlags(log.LstdFlags)
runtime.GOMAXPROCS(runtime.NumCPU())
gob.Register(new(KeyValue))
gob.Register(new(KeyGroups))
}
开发者ID:yonglehou,项目名称:gopark,代码行数:7,代码来源:context.go
示例16: StoreMsg
//StoreMsg
func (b *BoltStorage) StoreMsg(clientid string, m *proto.Publish) (string, error) {
storedMsgId := createStoredMsgId(clientid, m)
s := &StoredMsg{
lastupdated: time.Now(),
clientid: clientid,
Message: m,
status: StoredMsgSending,
}
w := new(bytes.Buffer)
gob.Register(&proto.Publish{})
gob.Register(&proto.BytesPayload{})
encoder := gob.NewEncoder(w)
err := encoder.Encode(s)
if err != nil {
return "", err
}
err = b.set(b.StoredMsgBucket, clientid, w.Bytes())
if err != nil {
return "", err
}
return storedMsgId, nil
}
开发者ID:nullboundary,项目名称:pesand,代码行数:28,代码来源:boltdb_storage.go
示例17: init
func init() {
gob.Register(driverInfo{})
gob.Register(flow{})
gob.Register(nodeDrivers{})
gob.Register(nodeFlows{})
gob.Register(nodeTriggers{})
}
开发者ID:1995parham,项目名称:FlyNest,代码行数:7,代码来源:dicts.go
示例18: init
// Register some common types. Repeated registration is ok.
func init() {
gob.Register(make(map[string]interface{}))
gob.Register(make(map[string]string))
gob.Register(make(map[string]int))
gob.Register(make([]interface{}, 0))
gob.Register(time.Duration(0))
}
开发者ID:hanjin8307,项目名称:circuit,代码行数:8,代码来源:gob.go
示例19: init
func init() {
gob.Register(Message{})
gob.Register(DeleteUserMessage{})
gob.Register(DeleteTorrentMessage{})
gob.Register(TorrentStatMessage{})
}
开发者ID:frazy,项目名称:babou,代码行数:7,代码来源:messages.go
示例20: Encode
func Encode(data interface{}) ([]byte, error) {
var err error
buf := bytes.NewBuffer(nil)
enc := gob.NewEncoder(buf)
switch data.(type) {
case map[string]interface{}:
nd := map[string]interface{}(data.(map[string]interface{}))
for _, v := range nd {
gob.Register(v)
}
err = enc.Encode(nd)
case map[interface{}]interface{}:
nd := map[string]interface{}(data.(map[string]interface{}))
for _, v := range nd {
gob.Register(v)
}
err = enc.Encode(nd)
case []interface{}:
nd := []interface{}(data.([]interface{}))
for _, v := range nd {
gob.Register(v)
}
err = enc.Encode(nd)
default:
}
err = enc.Encode(data)
if err != nil {
return []byte(""), err
}
return buf.Bytes(), nil
}
开发者ID:vChrysanthemum,项目名称:iron,代码行数:33,代码来源:utils.go
注:本文中的encoding/gob.Register函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论