#Whats this error

24 messages · Page 1 of 1 (latest)

trim sapphire
#

can anyone explain what does this error mean?

paper fog
#

share the full error message

trim sapphire
#

my bad

#
func (v voters) record_preferences() error {
    _, voted := global_ranking[v.name]
    if voted {
        return errors.New("Voter voted")
    }
    // fmt.Println(v.votes)
    fmt.Println(v.votes)
    global_ranking[v.name] = v.votes
    return nil
}
#

i think its in this part

#
type global_ranks map[voter_name]voter_ranks
var global_ranking global_ranks
flint willow
#

try this

func (v *voters) record_preferences() error {
    _, voted := global_ranking[v.name]
    if voted {
        return errors.New("Voter voted")
    }
    // fmt.Println(v.votes)
    fmt.Println(v.votes)
    global_ranking[v.name] = v.votes
    return nil
}
paper fog
flint willow
#

My hunch might have to use something like this
m := make(map[string]interface{})

trim sapphire
#

i found this

#

i think

#

its cause of the nil map assignment

flint willow
#

Okay. can you paste the code having changes that fixed the issue. would like to retrospect it.

paper fog
#

var global_ranking = global_ranks{}

trim sapphire
#

the artical covers only var and struct usage

#

not when assignment a type

trim sapphire
#

this

#

fixed the panic error

#

so this initializes the map i assume