2019-06-26 08:25
浏览 247


This question already has an answer here:

I'm writing a write method, to write an array of value to InfluxDB

What I would like is to be able to have something like:

func (influxClient *InfluxClient) Write(myArray []interface{}) (error) {
    // Insert into DB
    return nil


Where myArray could be an array with any objects inside

I tried to use myArray []interface{} to ommit myArray's type, but it doesn't work, I get:

Cannot use 'meters' (type []models.Meter) as type []interface{}

Is it possible to achieve it ?

How should I do ?


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

此问题已经存在 在这里有答案:</ p>

  • 对接口切片进行类型转换 5个答案 </ span> </ li> </ ul> </ div>

    我正在写一个write方法,将值数组写入InfluxDB </ p> < p>我想要的是这样的东西:</ p>

      func(influxClient * InfluxClient)Write(myArray [] interface {})(错误){
     </ code> </ pre> 

    其中 myArray </ code> 一个数组,里面有任何对象</ p>

    我尝试使用 myArray [] interface {} </ code>来省略myArray的类型,但是它不起作用,我得到:< / p >

     不能将'meters'(类型[] models.Meter)用作类型[] interface {} 
     </ code> </ pre> 

    有可能实现吗? </ p>

    我应该怎么做?</ p> </ div>

2条回答 默认 最新

相关推荐 更多相似问题