Skip to content
This repository has been archived by the owner on Oct 17, 2018. It is now read-only.

Commit

Permalink
Schema functions for namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitriy Gromov committed Jul 11, 2017
1 parent f3e059e commit 290f508
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions rules/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,41 @@ func (nss Namespaces) Version() int { return nss.version }

// Namespaces returns the list of namespaces.
func (nss Namespaces) Namespaces() []Namespace { return nss.namespaces }

// Schema returns the given Namespace in protobuf form
func (s NamespaceSnapshot) Schema() *schema.NamespaceSnapshot {
res := &schema.NamespaceSnapshot{
ForRulesetVersion: int32(s.forRuleSetVersion),
Tombstoned: s.tombstoned,
}

return res
}

// Schema returns the given Namespace in protobuf form
func (n Namespace) Schema() *schema.Namespace {
res := &schema.Namespace{
Name: string(n.name),
}

snapshots := make([]*schema.NamespaceSnapshot, len(n.snapshots))
for i, s := range n.snapshots {
snapshots[i] = s.Schema()
}
res.Snapshots = snapshots

return res
}

// Schema returns the given Namespaces slice in protobuf form.
func (nss Namespaces) Schema() *schema.Namespaces {
res := &schema.Namespaces{}

namespaces := make([]*schema.Namespace, len(nss.namespaces))
for i, n := range nss.namespaces {
namespaces[i] = n.Schema()
}
res.Namespaces = namespaces

return res
}

0 comments on commit 290f508

Please sign in to comment.