dousi0144
2018-01-08 12:06
浏览 105
已采纳

在golang中将地图转换为字符串

I am trying to find the best way to convert

map[string]string to type string . I tried converting to json with marshall to keep the format and then converting back to string but this was not successful. More specifically I am trying to convert a map containing keys and vals to a string to accommodate https://www.nomadproject.io/docs/job-specification/template.html#environment-variables https://github.com/hashicorp/nomad/blob/master/nomad/structs/structs.go#L3647

For example the final string should be like

LOG_LEVEL="x"
API_KEY="y"    

The map

m := map[string]string{
        "LOG_LEVEL": "x",
        "API_KEY": "y",
    }

图片转代码服务由CSDN问答提供 功能建议

我正在尝试找到转换的最佳方法

map [string] string 键入string。 我尝试使用marshall转换为json以保留格式,然后转换回字符串,但这未成功。 更具体地说,我正在尝试将包含键和值的映射转换为字符串以容纳 https://www.nomadproject.io/docs/job-specification/template.html#environment-variables https://github.com/hashicorp/nomad/blob/master/nomad/structs/structs.go#L3647

例如,最后一个字符串应类似于

  LOG_LEVEL =“ x” 
API_KEY =“ y” 
   
 
 

地图

  m:= map [string] string {
“ LOG_LEVEL”:“ x”,
“ API_KEY”:  “ y”,
} 
   
 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题