Skip to content

Commit

Permalink
autopush@1446656177
Browse files Browse the repository at this point in the history
  • Loading branch information
denkhaus committed Nov 4, 2015
1 parent 901d918 commit 23022ae
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 14 deletions.
18 changes: 13 additions & 5 deletions funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ import (
"github.com/fatih/structs"
)

////////////////////////////////////////////////////////////////////////////////
func Inspect(args ...interface{}) {
spew.Dump(args)
}

func newFuncMap() map[string]interface{} {
m := make(map[string]interface{})
m["base"] = path.Base
Expand All @@ -35,14 +30,27 @@ func newFuncMap() map[string]interface{} {
m["join"] = strings.Join
m["atoi"] = strconv.Atoi
m["where"] = where
m["inspect"] = Inspect
m["datetime"] = time.Now
m["toUpper"] = strings.ToUpper
m["toLower"] = strings.ToLower
m["contains"] = strings.Contains
m["replace"] = strings.Replace
m["scratchGetMVal"] = scratchGetMapValue
m["scratchGetSVal"] = scratchGetSliceValue
m["scratchSet"] = scratchSet
m["scratchAdd"] = scratchAdd
m["scratchMNames"] = scratchMapNames
m["scratchSNames"] = scratchSliceNames

return m
}

////////////////////////////////////////////////////////////////////////////////
func Inspect(args ...interface{}) {
spew.Dump(args)
}

////////////////////////////////////////////////////////////////////////////////
func get(ctx interface{}, action string, args ...interface{}) (interface{}, error) {
method := reflect.ValueOf(ctx).MethodByName(action)
Expand Down
13 changes: 6 additions & 7 deletions rmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@ func createTemplateCtx(meta *metadata.Client) (interface{}, error) {
if err != nil {
return nil, errors.Annotate(err, "get services")
}

servicesW := make([]ServiceWrap, 0)
for _, service := range services {
sw := ServiceWrap{service}
servicesW = append(servicesW, sw)
}

containers, err := meta.GetContainers()
if err != nil {
return nil, errors.Annotate(err, "get containers")
Expand All @@ -46,6 +39,12 @@ func createTemplateCtx(meta *metadata.Client) (interface{}, error) {
containersW = append(containersW, cw)
}

servicesW := make([]ServiceWrap, 0)
for _, service := range services {
sw := ServiceWrap{service}
servicesW = append(servicesW, sw)
}

ctx := map[string]interface{}{
"Services": servicesW,
"Containers": containersW,
Expand Down
60 changes: 60 additions & 0 deletions scratch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package main

var scrtsMap = make(map[string]map[string]interface{})
var scrtsSlice = make(map[string][]interface{})

//////////////////////////////////////////////////////////////////////////////
func scratchSet(scratch string, key string, value interface{}) {
if scr, ok := scrtsMap[scratch]; ok {
scr[key] = value
} else {
scrtsMap[scratch] = make(map[string]interface{})
scrtsMap[scratch][key] = value
}
}

//////////////////////////////////////////////////////////////////////////////
func scratchAdd(scratch string, value interface{}) {
if scr, ok := scrtsSlice[scratch]; ok {
scr = append(scr, value)
} else {
scrtsSlice[scratch] = make([]interface{}, 0)
scrtsSlice[scratch] = append(scrtsSlice[scratch], value)
}
}

//////////////////////////////////////////////////////////////////////////////
func scratchGetMapValue(scratch string, key string) interface{} {
if scr, ok := scrtsMap[scratch]; ok {
return scr[key]
}
return nil
}

//////////////////////////////////////////////////////////////////////////////
func scratchGetSliceValue(scratch string, key string) []interface{} {
if scr, ok := scrtsSlice[scratch]; ok {
return scr
}
return nil
}

//////////////////////////////////////////////////////////////////////////////
func scratchMapNames() []string {
nms := make([]string, 0)

for k, _ := range scrtsMap {
nms = append(nms, k)
}
return nms
}

//////////////////////////////////////////////////////////////////////////////
func scratchSliceNames() []string {
nms := make([]string, 0)

for k, _ := range scrtsSlice {
nms = append(nms, k)
}
return nms
}
3 changes: 1 addition & 2 deletions wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func (p ContainerWrap) PortInternal(idx int) (string, error) {
return "", nil
}

Inspect(p.Ports)
if idx >= len(p.Ports) {
return "", errors.Errorf("PortInternal: index %d out of range", idx)
}
Expand All @@ -51,7 +50,7 @@ func (p ContainerWrap) LabelByKey(key string) (string, error) {
return val, nil
}

printWarning("LabelByKey: key %q is not found", key)
printDebug("LabelByKey: key %q is not found", key)
return "", nil
}

Expand Down

0 comments on commit 23022ae

Please sign in to comment.