• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

dharnitski / cc-hosts / 15400738925

02 Jun 2025 07:12PM UTC coverage: 65.078%. First build
15400738925

push

github

dharnitski
bucket string

0 of 6 new or added lines in 2 files covered. (0.0%)

669 of 1028 relevant lines covered (65.08%)

0.73 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/cmd/search_lambda/main.go
1
package main
2

3
import (
4
        "context"
5
        "encoding/json"
6
        "time"
7

8
        "github.com/aws/aws-lambda-go/events"
9
        "github.com/aws/aws-lambda-go/lambda"
10
        "github.com/aws/aws-sdk-go-v2/config"
11
        "github.com/dharnitski/cc-hosts/access/aws"
12
        "github.com/dharnitski/cc-hosts/search"
13
)
14

15
var searcher *search.Searcher //nolint:gochecknoglobals
16

17
type Request struct {
18
        Domain string `json:"domain"`
19
}
20

21
// handler for basic lambda function.
22
func HandleRequest(ctx context.Context, event *Request) (*search.Result, error) {
×
23
        if event == nil {
×
24
                return &search.Result{}, nil
×
25
        }
×
26

27
        return searcher.GetTargets(ctx, event.Domain)
×
28
}
29

30
// handler for API Gateway proxy for lambda function.
31
func HandleGateway(ctx context.Context, request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
×
32
        domain, ok := request.PathParameters["domain"]
×
33
        if !ok {
×
34
                return events.APIGatewayProxyResponse{
×
35
                        StatusCode: 400,
×
36
                        Body:       "Missing domain parameter in path",
×
37
                }, nil
×
38
        }
×
39

40
        response, err := searcher.GetTargets(ctx, domain)
×
41
        if err != nil {
×
42
                return events.APIGatewayProxyResponse{
×
43
                        StatusCode: 500,
×
44
                        Body:       err.Error(),
×
45
                }, err
×
46
        }
×
47

48
        jsonResponse, err := json.Marshal(response)
×
49
        if err != nil {
×
50
                return events.APIGatewayProxyResponse{
×
51
                        StatusCode: 500,
×
52
                        Body:       "Error marshalling response",
×
53
                }, err
×
54
        }
×
55

56
        return events.APIGatewayProxyResponse{
×
57
                StatusCode: 200,
×
58
                Headers:    map[string]string{"Content-Type": "application/json"},
×
59
                Body:       string(jsonResponse),
×
60
        }, nil
×
61
}
62

63
func createSearcher(ctx context.Context) (*search.Searcher, error) {
×
64
        cfg, err := config.LoadDefaultConfig(ctx)
×
65
        if err != nil {
×
66
                return nil, err
×
67
        }
×
68

NEW
69
        return search.NewAwsSearcher(ctx, cfg, aws.Bucket)
×
70
}
71

72
func main() {
×
73
        var err error
×
74

×
75
        ctx := context.Background()
×
76
        // short timeout to load offsets
×
77
        ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
×
78
        defer cancel()
×
79

×
80
        searcher, err = createSearcher(ctx)
×
81
        if err != nil {
×
82
                panic(err)
×
83
        }
84

85
        lambda.Start(HandleGateway)
×
86
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc