-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
59 lines (46 loc) · 1.08 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"bufio"
"flag"
"fmt"
"io/ioutil"
"log"
"net/rpc"
"os"
"github.com/aws/aws-lambda-go/lambda/messages"
)
var host = flag.String("host", "localhost:1234", "The host where the lambda is running")
var ping = flag.Bool("ping", false, "Set the flag if you want to issue just a ping request")
func main() {
flag.Parse()
c, err := rpc.Dial("tcp", *host)
if err != nil {
log.Fatalln(err)
}
if *ping == true {
var result messages.PingResponse
request := &messages.PingRequest{}
err = c.Call("Function.Ping", request, &result)
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err.Error())
os.Exit(1)
}
os.Exit(0)
}
data, _ := ioutil.ReadAll(bufio.NewReader(os.Stdin))
var result messages.InvokeResponse
request := &messages.InvokeRequest{
Payload: data,
}
err = c.Call("Function.Invoke", request, &result)
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err.Error())
os.Exit(1)
}
if result.Error != nil {
fmt.Fprintf(os.Stderr, "%s\n", result.Error.Message)
os.Exit(1)
}
fmt.Printf("result: %v\n", string(result.Payload))
os.Exit(0)
}