加载文件并更改MySpan变量时,如何写回cfg文件?

I want to write the conf out to myconfig.gcfg, when I load the file and has change the Name string. How should I do? Sample config:

 [Span]
    Name = "DuraSpan" 
    MySpan = 4
    [Sys]
    SerialName = "/dev/ttyS0"

Go code:

import "gopkg.in/gcfg.v1"
        type Config struct {
            Span struct {
                Name string
                MySpan int
            }
            Sys struct{
                SerialName string
            }
        }
        var conf Config
        err := gcfg.ReadFileInto(&conf, "myconfig.gcfg")
        conf.Span.MySpan = 6

how to write back the change to file?

The library you choose don't do it for now, it has the task into the todo list, according to the documentation.

For the time being you should contact the developer to be aware of when the feature is scheduled, find another library or do it yourself.

You could use the go-yaml package to do it.