首页 \ 问答 \ 如何在golang中序列化为json嵌入结构(How to serialize to json embed structure in golang)

如何在golang中序列化为json嵌入结构(How to serialize to json embed structure in golang)

我刚刚开始学习Go,但我无法完成当前的任务。 我需要序列化由嵌套结构组成的结构。

package main

import (
    "encoding/json"
    "fmt"
)

type Metadata struct {
    model string
}

type Texture struct {
    url      string
    hash     string
    metadata *Metadata
}

type Response struct {
    SKIN *Texture
}

func main() {
    response := Response{}
    textures := &Texture{
        url: "http://ely.by",
        hash: "123123123123123123",
    }
    metadata := &Metadata{
        model: "slim",
    }

    textures.metadata = metadata
    response.SKIN = textures

    result, _ := json.Marshal(response)
    fmt.Println(string(result))
}

始终只输出{“SKIN”:{}}。 预期价值是:

{
    "SKIN": {
        "url": "http://ely.by",
        "hash": "123123123123123123",
        "metadata": {
            "model": "slim"
        }
    }
}

我在沙箱中创建了这个示例https://play.golang.org/p/IHktK6E33N


I'm just starting to learn Go, but I can not make out current task. I need to serialize the structure consisting of nested structures.

package main

import (
    "encoding/json"
    "fmt"
)

type Metadata struct {
    model string
}

type Texture struct {
    url      string
    hash     string
    metadata *Metadata
}

type Response struct {
    SKIN *Texture
}

func main() {
    response := Response{}
    textures := &Texture{
        url: "http://ely.by",
        hash: "123123123123123123",
    }
    metadata := &Metadata{
        model: "slim",
    }

    textures.metadata = metadata
    response.SKIN = textures

    result, _ := json.Marshal(response)
    fmt.Println(string(result))
}

Always output only {"SKIN":{}}. Expected value is:

{
    "SKIN": {
        "url": "http://ely.by",
        "hash": "123123123123123123",
        "metadata": {
            "model": "slim"
        }
    }
}

I created this example in a sandbox https://play.golang.org/p/IHktK6E33N.


原文:https://stackoverflow.com/questions/38027738
更新时间:2022-01-01 12:01

最满意答案

考虑到停机时间,我怀疑你能以简单的方式做到这一点。 也许你可以试试使用elasticdump 。 将索引数据移动到另一个实例可能会很痛苦,但是您可以使用python elasticsearch librarySO )。

否则,您可以将其作为对象存储,然后再导入它们。 将它存储为JSON ,已添加到Kibana 4.1 。 希望有助于。

管理kibana可视化和仪表板的明确指南。


I doubt you could do that in a simple manner, considering a downtime. Maybe you could give it a try by using elasticdump. Moving the index data to another instance could be a pain but then you could use the python elasticsearch library (SO).

Or else you could store it as Objects and then import them back. Storing it as a JSON, was added back in Kibana 4.1. Hope this helps.

A clear guide to managing kibana visualizations and dashboards.

相关问答

更多
  • Kibana 4.x中没有这样的功能。 您可以定义要打开的仪表板,并添加主要过滤器可视化过滤器。 您还可以编写一个简单的网页来调用嵌入式kibana仪表板,并在调用仪表板时注入查询。 There is no such feature in Kibana 4.x. You can define the dashboards you desire to be opened and add the filtering visualization from the main one. Also you can wr ...
  • 考虑到停机时间,我怀疑你能以简单的方式做到这一点。 也许你可以试试使用elasticdump 。 将索引数据移动到另一个实例可能会很痛苦,但是您可以使用python elasticsearch library ( SO )。 否则,您可以将其作为对象存储,然后再导入它们。 将它存储为JSON ,已添加到Kibana 4.1 。 希望这有助于。 管理kibana可视化和仪表板的明确指南。 I doubt you could do that in a simple manner, considering a d ...
  • 最终,没有找到快速的结果所以我不得不在Selenium和screencapturing之间混合。 感谢所有试图帮助的人! Now this is possible to export result in Kibana. create 'visualization' create 'Dashboard' using created visualizations. Then we can save or share the dashboard. In share we will get this report ...
  • 好的,我只是去了术语面板的源html代码文件并更改了它。 太简单.. Okay, I just went to the source html code file of the term panel and changed it. Too simple..
  • 您可以选择要在Kibana设置文件中使用的索引名称(Kibana 4;不确定3是否包含此选项)。 kibana.yml # Kibana uses an index in Elasticsearch to store saved searches, visualizations # and dashboards. It will create a new index if it doesn't already exist. kibana_index: ".kibana" 将 ...
  • 您无法使用ElasticSearch DSL查询直接构建Kibana可视化。 您可能想尝试: 新的可视化 在查询栏中写: service:http 在X轴上添加一个存储桶,选择术语agreggation,为主机选择您的字段。 You can't directly build Kibana visualization using ElasticSearch DSL query. You might want to try : New Visualization Write in the query bar : ...
  • 如果没有屏蔽,您可以尝试在只读模式下锁定.kibana索引: curl -XPUT 'localhost:9200/.kibana/_settings' -d '{ "index.blocks.read_only" : true }' 它运行良好,没有人可以保存/删除仪表板/搜索/可视化。 如果用户在仪表板上调整大小/移动内容,他可以通过在没有url中的参数的情况下为仪表板添加书签(或直接加载)来轻松重置。 您可以查看有关索引的更多选项: https : //www.elastic.co/guide/en ...
  • OpenTSDB是一个时间序列数据库。 对于度量标准组件,您可以将OpenTSDB与Elasticsearch一起使用。 您可以将Elasticsearch用于文本(可能是日志),将OpenTSDB用于度量标准。 如果您使用的是Logstash,则会有一个输出可以将日志中的指标导出到OpenTSDB中。 Kibana是Elasticsearch查询的可视化工具。 它可以帮助您搜索和查看存储在Elasticsearch中的数据。 它仅用于Elasticsearch。 如果您想要Elasticsearch和Op ...
  • 您可以使用cURL从命令行获取完整的Kibana元数据。 您需要拥有的只是访问Elasticsearch。 Elasticsearch在.kibana存储完整的Kibana元数据(默认情况下,如果您希望它存储在新索引中,则可以在kibana.yml中配置它)。 使用Elasticsearch GET API您可以检索index-patterns , visualizations , dashboards , kibana settings等。 获取Kibana可视化和仪表板的示例: curl -XGET " ...
  • 这对我有效,你必须指定略有不同的索引名称,默认情况下.kibana不起作用,也不会.kibana4: ./load.sh -url "search-theserver-5zxxn6zdjtlty74bw35irnppom.us-west-2.es.amazonaws.com" -index .kibana-4 (您不需要指定http://或端口号) This worked for me, you have to specify slightly different index name, by defau ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)