當前位置: 首頁>>代碼示例>>Golang>>正文


Golang structs.MessageType函數代碼示例

本文整理匯總了Golang中github.com/hashicorp/consul/consul/structs.MessageType函數的典型用法代碼示例。如果您正苦於以下問題:Golang MessageType函數的具體用法?Golang MessageType怎麽用?Golang MessageType使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了MessageType函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Apply

func (c *consulFSM) Apply(log *raft.Log) interface{} {
	buf := log.Data
	msgType := structs.MessageType(buf[0])

	// Check if this message type should be ignored when unknown. This is
	// used so that new commands can be added with developer control if older
	// versions can safely ignore the command, or if they should crash.
	ignoreUnknown := false
	if msgType&structs.IgnoreUnknownTypeFlag == structs.IgnoreUnknownTypeFlag {
		msgType &= ^structs.IgnoreUnknownTypeFlag
		ignoreUnknown = true
	}

	switch msgType {
	case structs.RegisterRequestType:
		return c.applyRegister(buf[1:], log.Index)
	case structs.DeregisterRequestType:
		return c.applyDeregister(buf[1:], log.Index)
	case structs.KVSRequestType:
		return c.applyKVSOperation(buf[1:], log.Index)
	case structs.SessionRequestType:
		return c.applySessionOperation(buf[1:], log.Index)
	case structs.ACLRequestType:
		return c.applyACLOperation(buf[1:], log.Index)
	case structs.TombstoneRequestType:
		return c.applyTombstoneOperation(buf[1:], log.Index)
	default:
		if ignoreUnknown {
			c.logger.Printf("[WARN] consul.fsm: ignoring unknown message type (%d), upgrade to newer version", msgType)
			return nil
		} else {
			panic(fmt.Errorf("failed to apply request: %#v", buf))
		}
	}
}
開發者ID:eicca,項目名稱:consul,代碼行數:35,代碼來源:fsm.go

示例2: Restore

func (c *consulFSM) Restore(old io.ReadCloser) error {
	defer old.Close()

	// Create a new state store
	state, err := NewStateStore(c.logOutput)
	if err != nil {
		return err
	}
	c.state.Close()
	c.state = state

	// Create a decoder
	var handle codec.MsgpackHandle
	dec := codec.NewDecoder(old, &handle)

	// Read in the header
	var header snapshotHeader
	if err := dec.Decode(&header); err != nil {
		return err
	}

	// Populate the new state
	msgType := make([]byte, 1)
	for {
		// Read the message type
		_, err := old.Read(msgType)
		if err == io.EOF {
			break
		} else if err != nil {
			return err
		}

		// Decode
		switch structs.MessageType(msgType[0]) {
		case structs.RegisterRequestType:
			var req structs.RegisterRequest
			if err := dec.Decode(&req); err != nil {
				return err
			}
			c.applyRegister(&req, header.LastIndex)

		case structs.KVSRequestType:
			var req structs.DirEntry
			if err := dec.Decode(&req); err != nil {
				return err
			}
			if err := c.state.KVSRestore(&req); err != nil {
				return err
			}

		default:
			return fmt.Errorf("Unrecognized msg type: %v", msgType)
		}
	}

	return nil
}
開發者ID:rayleyva,項目名稱:consul,代碼行數:57,代碼來源:fsm.go

示例3: Apply

func (c *consulFSM) Apply(log *raft.Log) interface{} {
	buf := log.Data
	switch structs.MessageType(buf[0]) {
	case structs.RegisterRequestType:
		return c.decodeRegister(buf[1:], log.Index)
	case structs.DeregisterRequestType:
		return c.applyDeregister(buf[1:], log.Index)
	case structs.KVSRequestType:
		return c.applyKVSOperation(buf[1:], log.Index)
	default:
		panic(fmt.Errorf("failed to apply request: %#v", buf))
	}
}
開發者ID:rayleyva,項目名稱:consul,代碼行數:13,代碼來源:fsm.go

示例4: handleLogCommand

func handleLogCommand(log raft.Log) {
	buf := log.Data
	if len(buf) > 0 {
		msgType := structs.MessageType(buf[0])
		switch msgType {
		case structs.RegisterRequestType:
			var data structs.RegisterRequest
			printData(log, buf[1:], &data)
		case structs.DeregisterRequestType:
			var data structs.DeregisterRequest
			printData(log, buf[1:], &data)
		case structs.KVSRequestType:
			var data structs.KVSRequest
			printData(log, buf[1:], &data)
		case structs.SessionRequestType:
			var data structs.SessionRequest
			printData(log, buf[1:], &data)
		case structs.ACLRequestType:
			var data structs.ACLRequest
			printData(log, buf[1:], &data)
		case structs.TombstoneRequestType:
			var data structs.TombstoneRequest
			printData(log, buf[1:], &data)
		case structs.CoordinateBatchUpdateType, 134:
			var data structs.Coordinates
			printData(log, buf[1:], &data)
		case structs.PreparedQueryRequestType:
			var data structs.PreparedQueryRequest
			printData(log, buf[1:], &data)
		default:
			kingpin.Errorf("Unknown msg type %d", msgType)
			printMsgPackData(log, reflect.Indirect(reflect.ValueOf(msgType)).Type().Name(), buf[1:])
		}

	} else {
		printJson(log, "", log.Data)
	}
}
開發者ID:outbrain,項目名稱:consul-raftdb-reader,代碼行數:38,代碼來源:main.go

示例5: Restore

func (c *consulFSM) Restore(old io.ReadCloser) error {
	defer old.Close()

	// Create a new state store
	stateNew, err := state.NewStateStore(c.gc)
	if err != nil {
		return err
	}
	c.state = stateNew

	// Set up a new restore transaction
	restore := c.state.Restore()
	defer restore.Abort()

	// Create a decoder
	dec := codec.NewDecoder(old, msgpackHandle)

	// Read in the header
	var header snapshotHeader
	if err := dec.Decode(&header); err != nil {
		return err
	}

	// Populate the new state
	msgType := make([]byte, 1)
	for {
		// Read the message type
		_, err := old.Read(msgType)
		if err == io.EOF {
			break
		} else if err != nil {
			return err
		}

		// Decode
		switch structs.MessageType(msgType[0]) {
		case structs.RegisterRequestType:
			var req structs.RegisterRequest
			if err := dec.Decode(&req); err != nil {
				return err
			}
			if err := restore.Registration(header.LastIndex, &req); err != nil {
				return err
			}

		case structs.KVSRequestType:
			var req structs.DirEntry
			if err := dec.Decode(&req); err != nil {
				return err
			}
			if err := restore.KVS(&req); err != nil {
				return err
			}

		case structs.TombstoneRequestType:
			var req structs.DirEntry
			if err := dec.Decode(&req); err != nil {
				return err
			}

			// For historical reasons, these are serialized in the
			// snapshots as KV entries. We want to keep the snapshot
			// format compatible with pre-0.6 versions for now.
			stone := &state.Tombstone{
				Key:   req.Key,
				Index: req.ModifyIndex,
			}
			if err := restore.Tombstone(stone); err != nil {
				return err
			}

		case structs.SessionRequestType:
			var req structs.Session
			if err := dec.Decode(&req); err != nil {
				return err
			}
			if err := restore.Session(&req); err != nil {
				return err
			}

		case structs.ACLRequestType:
			var req structs.ACL
			if err := dec.Decode(&req); err != nil {
				return err
			}
			if err := restore.ACL(&req); err != nil {
				return err
			}

		case structs.CoordinateBatchUpdateType:
			var req structs.Coordinates
			if err := dec.Decode(&req); err != nil {
				return err

			}
			if err := restore.Coordinates(header.LastIndex, req); err != nil {
				return err
			}

		case structs.PreparedQueryRequestType:
//.........這裏部分代碼省略.........
開發者ID:catroot,項目名稱:consul,代碼行數:101,代碼來源:fsm.go


注:本文中的github.com/hashicorp/consul/consul/structs.MessageType函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。