package types import ( "bytes" "github.com/BurntSushi/toml" ) const SchemaVersion = 1 type Package struct { GoPackagePath string `toml:"-"` Version string `toml:"version"` Hash string `toml:"hash"` ReplacedPath string `toml:"replaced,omitempty"` } type Output struct { SchemaVersion int `toml:"schema"` Mod map[string]*Package `toml:"mod"` } func Marshal(pkgs []*Package) ([]byte, error) { out := &Output{ SchemaVersion: SchemaVersion, Mod: make(map[string]*Package), } for _, pkg := range pkgs { out.Mod[pkg.GoPackagePath] = pkg } var buf bytes.Buffer e := toml.NewEncoder(&buf) err := e.Encode(out) if err != nil { return nil, err } return buf.Bytes(), nil }