-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
37 lines (32 loc) · 882 Bytes
/
main.go
File metadata and controls
37 lines (32 loc) · 882 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
package main
import (
"context"
"fmt"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
"io/ioutil"
"net/http"
"regexp"
)
func getHoroscope(sign string) string {
var horoscope = ""
re := regexp.MustCompile(`horoscope\s=?\s(.*)?;`)
response, err := http.Get("http://astrology.kudosmedia.net/index.php/m/" + sign + "?day=today")
if err != nil {
horoscope = fmt.Sprintf("The request failed, error: %s", err)
} else {
data, _ := ioutil.ReadAll(response.Body)
horoscope = re.FindStringSubmatch(string(data))[1]
}
return horoscope
}
func handler(ctx context.Context, request events.APIGatewayProxyRequest) (*events.APIGatewayProxyResponse, error) {
res := getHoroscope(request.QueryStringParameters["sign"])
return &events.APIGatewayProxyResponse{
StatusCode: 200,
Body: res,
}, nil
}
func main() {
lambda.Start(handler)
}