• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang internal.Command类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/influxdb/influxdb/meta/internal.Command的典型用法代码示例。如果您正苦于以下问题:Golang Command类的具体用法?Golang Command怎么用?Golang Command使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Command类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: Apply

func (fsm *storeFSM) Apply(l *raft.Log) interface{} {
	var cmd internal.Command
	if err := proto.Unmarshal(l.Data, &cmd); err != nil {
		panic(fmt.Errorf("cannot marshal command: %x", l.Data))
	}

	// Lock the store.
	s := (*Store)(fsm)
	s.mu.Lock()
	defer s.mu.Unlock()

	err := func() interface{} {
		switch cmd.GetType() {
		case internal.Command_CreateNodeCommand:
			return fsm.applyCreateNodeCommand(&cmd)
		case internal.Command_DeleteNodeCommand:
			return fsm.applyDeleteNodeCommand(&cmd)
		case internal.Command_CreateDatabaseCommand:
			return fsm.applyCreateDatabaseCommand(&cmd)
		case internal.Command_DropDatabaseCommand:
			return fsm.applyDropDatabaseCommand(&cmd)
		case internal.Command_CreateRetentionPolicyCommand:
			return fsm.applyCreateRetentionPolicyCommand(&cmd)
		case internal.Command_DropRetentionPolicyCommand:
			return fsm.applyDropRetentionPolicyCommand(&cmd)
		case internal.Command_SetDefaultRetentionPolicyCommand:
			return fsm.applySetDefaultRetentionPolicyCommand(&cmd)
		case internal.Command_UpdateRetentionPolicyCommand:
			return fsm.applyUpdateRetentionPolicyCommand(&cmd)
		case internal.Command_CreateShardGroupCommand:
			return fsm.applyCreateShardGroupCommand(&cmd)
		case internal.Command_DeleteShardGroupCommand:
			return fsm.applyDeleteShardGroupCommand(&cmd)
		case internal.Command_CreateContinuousQueryCommand:
			return fsm.applyCreateContinuousQueryCommand(&cmd)
		case internal.Command_DropContinuousQueryCommand:
			return fsm.applyDropContinuousQueryCommand(&cmd)
		case internal.Command_CreateUserCommand:
			return fsm.applyCreateUserCommand(&cmd)
		case internal.Command_DropUserCommand:
			return fsm.applyDropUserCommand(&cmd)
		case internal.Command_UpdateUserCommand:
			return fsm.applyUpdateUserCommand(&cmd)
		case internal.Command_SetPrivilegeCommand:
			return fsm.applySetPrivilegeCommand(&cmd)
		case internal.Command_SetAdminPrivilegeCommand:
			return fsm.applySetAdminPrivilegeCommand(&cmd)
		case internal.Command_SetDataCommand:
			return fsm.applySetDataCommand(&cmd)
		default:
			panic(fmt.Errorf("cannot apply command: %x", l.Data))
		}
	}()

	// Copy term and index to new metadata.
	fsm.data.Term = l.Term
	fsm.data.Index = l.Index

	return err
}
开发者ID:radcheb,项目名称:influxdb,代码行数:60,代码来源:store.go


示例2: main

func main() {
	qlog.SetOutputLevel(0)
	db, err := raftboltdb.NewBoltStore(PATH)
	lastIdx, err := db.LastIndex()
	firtIdx, err := db.FirstIndex()
	for i := int(firtIdx); i <= int(lastIdx); i++ {
		log := new(raft.Log)
		if err = db.GetLog(uint64(i), log); err != nil {
			qlog.Debug(err)
			continue
		}

		switch log.Type {
		case raft.LogCommand:
			qlog.Info("The raftlog type is LogCommand")
			var cmd internal.Command
			if err := proto.Unmarshal(log.Data, &cmd); err != nil {
				qlog.Debug(err)
				continue
			}
			command := cmd.GetType()
			qlog.Infof("The command is: %s", command)
			if command == internal.Command_CreateNodeCommand {
				ext, _ := proto.GetExtension(&cmd, internal.E_CreateNodeCommand_Command)
				v, ok := ext.(*internal.CreateNodeCommand)
				if !ok {
					continue
				}
				qlog.Debug("v.GetHost()", v.GetHost())
			}

			if command == internal.Command_CreateDatabaseCommand {
				ext, _ := proto.GetExtension(&cmd, internal.E_CreateDatabaseCommand_Command)
				v, ok := ext.(*internal.CreateDatabaseCommand)
				if !ok {
					continue
				}
				qlog.Debug("v.GetName()", v.GetName())
				qlog.Debug("v.String()", v.String())
			}

			if command == internal.Command_CreateRetentionPolicyCommand {
				ext, _ := proto.GetExtension(&cmd, internal.E_CreateRetentionPolicyCommand_Command)
				v, ok := ext.(*internal.CreateRetentionPolicyCommand)
				if !ok {
					continue
				}
				qlog.Debug("v.GetDatabase()", v.GetDatabase())
				qlog.Debug("v.GetRetentionPolicy()", v.GetRetentionPolicy())
				qlog.Debug("v.String()", v.String())
			}

			if command == internal.Command_SetDefaultRetentionPolicyCommand {
				ext, _ := proto.GetExtension(&cmd, internal.E_SetDefaultRetentionPolicyCommand_Command)
				v, ok := ext.(*internal.SetDefaultRetentionPolicyCommand)
				if !ok {
					continue
				}
				qlog.Debug("v.GetDatabase()", v.GetDatabase())
				qlog.Debug("v.GetName()", v.GetName())
				qlog.Debug("v.String()", v.String())
			}

		case raft.LogNoop:
			qlog.Info("The raftlog type is LogNoop")
		case raft.LogAddPeer:
			qlog.Info("The raftlog type is LogAddPeer")
			peers := decodePeers(log.Data)

			if len(peers) == 0 {
				qlog.Debug("peers == 0")
				continue
			}
			qlog.Infof("peers is:%s", peers)

		case raft.LogRemovePeer:
			qlog.Info("The raftlog type is LogAddPeer")
		}
	}
	return
}
开发者ID:li-ang,项目名称:influxdb_test,代码行数:81,代码来源:main.go



注:本文中的github.com/influxdb/influxdb/meta/internal.Command类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang internal.Response类代码示例发布时间:2022-05-23
下一篇:
Golang meta.UserInfo类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap