3

I am having difficulty in what should be a trivial task of creating an interface array. Here is my code,

var result float64
for i := 0; i < len(diff); i++ {
    result += diff[i]
}
result = 1 / (1 + math.Sqrt(result))

id1 := user1.UserId
id2 := user2.UserId

user1.Similar[id2] = [2]interface{id2, result}
user2.Similar[id1] = [2]interface{id1, result}

result is a float and user*.UserId is an int.

My error message is

syntax error: name list not allowed in interface type

1 Answer 1

7

For example,

package main

import (
    "fmt"
)

func main() {
    x, y := 1, "@"
    a := [2]interface{}{x, y}
    fmt.Println(a)
    b := [2]interface{}{0, "x"}
    fmt.Println(b)
}

Output:

[1 @]
[0 x]
Sign up to request clarification or add additional context in comments.

1 Comment

thank you. I ended up declaring a struct because it will always be {int, float64} pair but that's the right answer!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.