mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-04-20 19:38:39 +00:00
Add custom JSON representation of PublishedRepo. #116
This commit is contained in:
@@ -3,6 +3,7 @@ package deb
|
||||
import (
|
||||
"bytes"
|
||||
"code.google.com/p/go-uuid/uuid"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/smira/aptly/aptly"
|
||||
"github.com/smira/aptly/database"
|
||||
@@ -255,6 +256,40 @@ func NewPublishedRepo(storage, prefix, distribution string, architectures []stri
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// MarshalJSON requires object to be "loeaded completely"
|
||||
func (p *PublishedRepo) MarshalJSON() ([]byte, error) {
|
||||
type sourceInfo struct {
|
||||
Component, Name string
|
||||
}
|
||||
|
||||
sources := []sourceInfo{}
|
||||
for component, item := range p.sourceItems {
|
||||
name := ""
|
||||
if item.snapshot != nil {
|
||||
name = item.snapshot.Name
|
||||
} else if item.localRepo != nil {
|
||||
name = item.localRepo.Name
|
||||
} else {
|
||||
panic("no snapshot/local repo")
|
||||
}
|
||||
sources = append(sources, sourceInfo{
|
||||
Component: component,
|
||||
Name: name,
|
||||
})
|
||||
}
|
||||
|
||||
return json.Marshal(map[string]interface{}{
|
||||
"Architectures": p.Architectures,
|
||||
"Distribution": p.Distribution,
|
||||
"Label": p.Label,
|
||||
"Origin": p.Origin,
|
||||
"Prefix": p.Prefix,
|
||||
"SourceKind": p.SourceKind,
|
||||
"Sources": sources,
|
||||
"Storage": p.Storage,
|
||||
})
|
||||
}
|
||||
|
||||
// String returns human-readable represenation of PublishedRepo
|
||||
func (p *PublishedRepo) String() string {
|
||||
var sources = []string{}
|
||||
|
||||
Reference in New Issue
Block a user