Skip to content

Commit

Permalink
support sorted sets
Browse files Browse the repository at this point in the history
  • Loading branch information
HeavyHorst committed Oct 19, 2020
1 parent 2df9f57 commit 8d36e4f
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions pkg/template/template_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,40 @@ import (
"github.com/HeavyHorst/remco/pkg/template/fileutil"
)

type interfaceSet struct {
S map[interface{}]struct{}
}
type interfaceSet map[string]struct{}

func (s *interfaceSet) Append(value interface{}) string {
s.S[value] = struct{}{}
func (s interfaceSet) Append(value interface{}) string {
v := fmt.Sprintf("%v", value)
s[v] = struct{}{}
return ""
}

func (s *interfaceSet) Remove(value string) string {
delete(s.S, value)
func (s interfaceSet) Remove(value string) string {
v := fmt.Sprintf("%v", value)
delete(s, v)
return ""
}

func (s *interfaceSet) Contains(value interface{}) bool {
_, c := s.S[value]
func (s interfaceSet) Contains(value interface{}) bool {
v := fmt.Sprintf("%v", value)
_, c := s[v]
return c
}

func (s *interfaceSet) toSet() []interface{} {
var i []interface{}
for k := range s.S {
func (s interfaceSet) toSet() []string {
var i []string
for k := range s {
i = append(i, k)
}

return i
}

func (s *interfaceSet) MarshalYAML() (interface{}, error) {
func (s interfaceSet) MarshalYAML() (interface{}, error) {
return s.toSet(), nil
}

func (s *interfaceSet) MarshalJSON() ([]byte, error) {
func (s interfaceSet) MarshalJSON() ([]byte, error) {
return json.Marshal(s.toSet())
}

Expand Down Expand Up @@ -139,10 +140,8 @@ func createMap() templateMap {
return tm
}

func createSet() *interfaceSet {
return &interfaceSet{
S: make(map[interface{}]struct{}),
}
func createSet() interfaceSet {
return make(map[string]struct{})
}

func lookupSRV(service, proto, name string) ([]*net.SRV, error) {
Expand Down

0 comments on commit 8d36e4f

Please sign in to comment.