当前位置: 首页>>代码示例>>Golang>>正文


Golang ResponseObject.CfgModified方法代码示例

本文整理汇总了Golang中github.com/tmaiaroto/discfg/config.ResponseObject.CfgModified方法的典型用法代码示例。如果您正苦于以下问题:Golang ResponseObject.CfgModified方法的具体用法?Golang ResponseObject.CfgModified怎么用?Golang ResponseObject.CfgModified使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/tmaiaroto/discfg/config.ResponseObject的用法示例。


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

示例1: Info

// Info about the configuration including global version/state and modified time
func Info(opts config.Options) config.ResponseObject {
	resp := config.ResponseObject{
		Action: "info",
	}

	if opts.CfgName != "" {
		// Just get the root key
		opts.Key = "/"

		storageResponse, err := storage.Get(opts)
		if err != nil {
			resp.Error = err.Error()
		} else {
			// Debating putting the item value on here... (allowing users to store values on the config or "root")
			// resp.Item = storageResponse
			// Set the configuration version and modified time on the response
			// Item.CfgVersion and Item.CfgModifiedNanoseconds are not included in the JSON output
			resp.CfgVersion = storageResponse.CfgVersion
			resp.CfgModified = 0
			resp.CfgModifiedNanoseconds = storageResponse.CfgModifiedNanoseconds
			// Modified in seconds
			resp.CfgModified = storageResponse.CfgModifiedNanoseconds / int64(time.Second)
			// Modified parsed
			modified := time.Unix(0, storageResponse.CfgModifiedNanoseconds)
			resp.CfgModifiedParsed = modified.Format(time.RFC3339)

			// Set information about the storage engine
			resp.CfgStorage.InterfaceName = opts.StorageInterfaceName
			resp.CfgStorage.Name = storage.Name(opts)
			resp.CfgStorage.Options = storage.Options(opts)

			// Get the status (only applicable for some storage interfaces, such as DynamoDB)
			resp.CfgState, err = storage.ConfigState(opts)
			if err != nil {
				resp.Error = err.Error()
			} else {
				var buffer bytes.Buffer
				buffer.WriteString(opts.CfgName)
				if resp.CfgState != "" {
					buffer.WriteString(" (")
					buffer.WriteString(resp.CfgState)
					buffer.WriteString(")")
				}
				buffer.WriteString(" version ")
				buffer.WriteString(strconv.FormatInt(resp.CfgVersion, 10))
				buffer.WriteString(" last modified ")
				buffer.WriteString(modified.Format(time.RFC1123))
				resp.Message = buffer.String()
				buffer.Reset()
			}
		}
	} else {
		resp.Error = NotEnoughArgsMsg
	}
	return resp
}
开发者ID:tmaiaroto,项目名称:discfg,代码行数:57,代码来源:commands.go


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