From 2b96b761d19f3f684c3f33feb0ff1e425a36faf1 Mon Sep 17 00:00:00 2001 From: derek mcquay Date: Tue, 16 Feb 2016 20:06:44 -0800 Subject: [PATCH] POST translate string -> vain.Vcs --- vain.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/vain.go b/vain.go index eb59358..4385fa4 100644 --- a/vain.go +++ b/vain.go @@ -3,7 +3,10 @@ // The executable, cmd/ysvd, is located in the respective subdirectory. package vain -import "fmt" +import ( + "encoding/json" + "fmt" +) type vcs int @@ -62,3 +65,16 @@ func (p Package) String() string { p.Repo, ) } + +func (p *Package) UnmarshalJSON(b []byte) (err error) { + pkg := struct { + Vcs string + Repo string + }{} + err = json.Unmarshal(b, &pkg) + if err != nil { + return err + } + p.Vcs, p.Repo = labelToVcs[pkg.Vcs], pkg.Repo + return nil +}