-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d9ee34d
commit 149acf3
Showing
6 changed files
with
159 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
package handler | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"time" | ||
) | ||
|
||
func HandleMathMax(req Request) (string, map[string]string, error) { | ||
defer recoverFailure(req) | ||
|
||
switch req.RequestType { | ||
case "Create": | ||
fmt.Println("CREATING Max") | ||
fmt.Printf("req %+v\n", req) | ||
return CreateMathMax(req) | ||
case "Update": | ||
fmt.Println("UPDATING Max") | ||
fmt.Printf("req %+v\n", req) | ||
return UpdateMathMax(req) | ||
case "Delete": | ||
fmt.Println("no need to delete") | ||
fmt.Printf("req %+v\n", req) | ||
return req.PhysicalResourceId, nil, nil | ||
} | ||
|
||
return "", nil, fmt.Errorf("unknown RequestType: %s", req.RequestType) | ||
} | ||
|
||
func HandleMathMin(req Request) (string, map[string]string, error) { | ||
defer recoverFailure(req) | ||
|
||
switch req.RequestType { | ||
case "Create": | ||
fmt.Println("CREATING Min") | ||
fmt.Printf("req %+v\n", req) | ||
return CreateMathMin(req) | ||
case "Update": | ||
fmt.Println("UPDATING Min") | ||
fmt.Printf("req %+v\n", req) | ||
return UpdateMathMin(req) | ||
case "Delete": | ||
fmt.Println("no need to delete") | ||
fmt.Printf("req %+v\n", req) | ||
return req.PhysicalResourceId, nil, nil | ||
} | ||
|
||
return "", nil, fmt.Errorf("unknown RequestType: %s", req.RequestType) | ||
} | ||
|
||
func CreateMathMax(req Request) (string, map[string]string, error) { | ||
val, err := mathMax(req) | ||
if err != nil { | ||
return "invalid", nil, err | ||
} | ||
|
||
return fmt.Sprintf("mathmax-%d", time.Now().UnixNano()), map[string]string{ | ||
"Value": val, | ||
}, nil | ||
} | ||
|
||
func UpdateMathMax(req Request) (string, map[string]string, error) { | ||
val, err := mathMax(req) | ||
if err != nil { | ||
return "invalid", nil, err | ||
} | ||
|
||
return req.PhysicalResourceId, map[string]string{ | ||
"Value": val, | ||
}, nil | ||
} | ||
|
||
func CreateMathMin(req Request) (string, map[string]string, error) { | ||
val, err := mathMin(req) | ||
if err != nil { | ||
return "invalid", nil, err | ||
} | ||
|
||
return fmt.Sprintf("mathmin-%d", time.Now().UnixNano()), map[string]string{ | ||
"Value": val, | ||
}, nil | ||
} | ||
|
||
func UpdateMathMin(req Request) (string, map[string]string, error) { | ||
val, err := mathMin(req) | ||
if err != nil { | ||
return "invalid", nil, err | ||
} | ||
|
||
return req.PhysicalResourceId, map[string]string{ | ||
"Value": val, | ||
}, nil | ||
} | ||
|
||
func mathMax(req Request) (string, error) { | ||
x, y, err := parseXY(req) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
if y > x { | ||
x = y | ||
} | ||
|
||
return strconv.Itoa(x), nil | ||
} | ||
|
||
func mathMin(req Request) (string, error) { | ||
x, y, err := parseXY(req) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
if y < x { | ||
x = y | ||
} | ||
|
||
return strconv.Itoa(x), nil | ||
} | ||
|
||
func parseXY(req Request) (int, int, error) { | ||
xStr := req.ResourceProperties["X"].(string) | ||
yStr := req.ResourceProperties["Y"].(string) | ||
|
||
x, err := strconv.Atoi(xStr) | ||
if err != nil { | ||
return 0, 0, err | ||
} | ||
|
||
y, err := strconv.Atoi(yStr) | ||
if err != nil { | ||
return 0, 0, err | ||
} | ||
return x, y, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters