Files

39 lines
523 B
Go
Raw Normal View History

2021-12-28 10:38:02 +08:00
package utils
import (
"gopkg.in/yaml.v2"
"os"
"testing"
)
2021-12-28 10:57:13 +08:00
type Mysql struct {
Host string
}
2021-12-28 10:38:02 +08:00
type config struct {
2021-12-28 10:57:13 +08:00
Version int `yaml:"version"`
Mapping *Mysql `yaml:"mapping"`
2021-12-28 10:38:02 +08:00
}
func TestNewFile(t *testing.T) {
file, err := os.OpenFile("test.yml", os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
t.Log(err)
return
}
defer file.Close()
enc := yaml.NewEncoder(file)
err = enc.Encode(config{
Version: 7,
2021-12-28 10:57:13 +08:00
Mapping: &Mysql{
Host: "123",
2021-12-28 10:38:02 +08:00
},
})
if err != nil {
t.Log(err)
return
}
}