forked from michaelbammeke/network-lambda
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
51 lines (40 loc) · 851 Bytes
/
Copy pathmain.go
File metadata and controls
51 lines (40 loc) · 851 Bytes
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
package main
import (
"context"
"fmt"
"io/ioutil"
"net"
"time"
"github.com/aws/aws-lambda-go/lambda"
"gopkg.in/yaml.v2"
)
const (
timeoutSecs = 5
)
type Conf struct {
Endpoints []Endpoint
}
type Endpoint struct {
Host string
Port string
}
func HandleRequest(ctx context.Context) (err error) {
// Read yaml file
yamlFile, _ := ioutil.ReadFile("test.yaml")
urlList := &Conf{}
_ = yaml.Unmarshal(yamlFile, urlList)
for _, endpoint := range urlList.Endpoints {
timeout := timeoutSecs * time.Second
url := fmt.Sprintf("%s:%s", endpoint.Host, endpoint.Port)
_, err = net.DialTimeout("tcp", url, timeout)
if err == nil {
fmt.Printf("connection to %s SUCCESSFUL!!!\n", url)
} else {
fmt.Printf("connection to %s FAILED!!! -- REASON: %v\n", url, err)
}
}
return nil
}
func main() {
lambda.Start(HandleRequest)
}