如何在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
最满意答案
考虑到停机时间,我怀疑你能以简单的方式做到这一点。 也许你可以试试使用elasticdump 。 将索引数据移动到另一个实例可能会很痛苦,但是您可以使用
python elasticsearch library
( SO )。否则,您可以将其作为对象存储,然后再导入它们。 将它存储为
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 inKibana 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 ...
-
Kibana仪表板:术语面板(Kibana dashboard: term panel)[2022-05-20]
好的,我只是去了术语面板的源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 ...