/
lambda.go
107 lines (94 loc) · 2.44 KB
/
lambda.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package core
import (
"github.com/aws/aws-sdk-go/service/lambda"
"time"
)
// Lambda represents a AWS Lambda with all
// properties need by lambda-monitor to run
type Lambda struct {
name string
lastModified time.Time
codeSha256 string
codeSize uint32
description string
variables map[string]string
arn string
handler string
revisionId string
role string
runtime string
timeout uint32
tracingConfig map[string]string
version string
}
// GetName allows others to retrieve Lambda name
// TODO add tests
func (l Lambda) GetName() string {
return l.name
}
// LambdaBuilder knows how to build a Lambda from a FunctionConfiguration
// provided by AWS package
// TODO add tests
func LambdaBuilder(awsFunction *lambda.FunctionConfiguration) (lambda *Lambda) {
return &Lambda{
name: *awsFunction.FunctionName,
}
}
// Lambdas stores a collection of Lambdas
// and collection related funcs to operate over them
type Lambdas struct {
lambdas []Lambda
}
// Get returns the internal array of lambdas from Lambdas type
// TODO add tests
func (lambdas Lambdas) Get() []Lambda {
return lambdas.lambdas
}
// Set replaces the internal array of lambdas
// TODO add tests
func (lambdas Lambdas) Set(newLambdas []Lambda) {
lambdas.lambdas = newLambdas
}
// Size returns the amount of lambdas found
// TODO add tests
func (lambdas Lambdas) Size() int {
return len(lambdas.lambdas)
}
// Size returns the amount of lambdas found
// TODO add tests
func (lambdas *Lambdas) Put(lambda Lambda) {
lambdas.lambdas = append(lambdas.lambdas, lambda)
}
// GetIterator retrieves an iterator to the
// current Lambdass
// TODO add tests
func (lambdas Lambdas) GetIterator() *LambdasIterator {
return &LambdasIterator{
lambdas: lambdas,
head: -1,
}
}
// LambdasIterator contains a temporary data
// to iterate over a Lambdas type
type LambdasIterator struct {
lambdas Lambdas
head int
}
// Next moves the internal head of the iterator to the
// next position if its possible
// TODO add tests
func (iterator *LambdasIterator) Next() bool {
if iterator.head < len(iterator.lambdas.Get())-1 {
iterator.head++
return true
}
return false
}
// Retrieves the lambda stored in the current head position
// TODO add tests
func (iterator LambdasIterator) Get() (lambda Lambda) {
if iterator.head >= 0 && iterator.head < len(iterator.lambdas.Get()) {
lambda = iterator.lambdas.Get()[iterator.head]
}
return
}