A function as a Glue
Besides writing a simple processor, the technique in this section is one of the simplest forms of using functions. We have a bank backend with REST APIs exposed. So we write a function as a Glue to hide the complex interface of the backend. In this example, we use Go
as the language to implement the function.
The scenario is that we have a REST API server and we want to unify it with another similar service. In the example in this chapter, we have two banking backends with different ways of interaction. The first one is a web-based UI without a REST interface, another one is the REST API in this section:
func main() { input := os.Args[1] // OpenWhisk params are key/value paris params := map[string]interface{}{} err := json.Unmarshal([]byte(input), params) if err != nil { fmt.Printf(`{"error":"%s", "input": "%s"}`, err.Error(), string(input)) os.Exit(-1) } entry := Entry{ Account: Account{ Id: params["accountId"].(string), }, Amount...