示例
package main
import (
"fmt"
encoder "github.com/zwgblue/yaml-encoder"
)
type DBConfig struct {
Username string `comment:"this is the username of database"`
Password string `comment:"this is the password of database"`
}
func main(){
config := DBConfig{
Username: "root",
Password: "xxxxxx",
}
encoder := encoder.NewEncoder(config, encoder.WithComments(encoder.CommentsOnHead))
content, _ := encoder.Encode()
fmt.Printf("%s", content)
}
输出:
# this is the username of database
username: root
# this is the password of database
password: xxxxxx