如何使用指针更改属性值

I am trying to change a value within a struct. Unfortunately, the value in "" ==>", flow" doesn't change. I don't understand why.

Can you help me to explain why the pointer doesn't correspond in Slice. May be I must write a slice of pointer ?

Thank you in advance.

package main

import (
    "fmt"
)

type Foo struct {
    value float64
}

var flows []Foo;

func AddFoo(foo Foo) {
    flows = append(flows, foo)
}

func UpdateFoo(stream *Foo) {
    stream.value = 5.00
}

func main() {
    x := Foo{1.00}
    AddFoo(x)
    UpdateFoo(&x)
    fmt.Println(x)


    for _, flow := range flows {
        fmt.Println(" ==>", flow)
        }
}

In your function AddFoo you are adding a copy of Foo to your slice, then in UpdateFoo you are changing x which is not the same variable as the one in the slice.

Yes, if you'd create a slice of pointers it'd work.