forked from shykes/hello
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
57 lines (53 loc) · 1.24 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
// A Dagger module to say hello to the world
package main
import (
"context"
"fmt"
"hello/internal/dagger"
"strings"
)
var defaultFigletContainer = dag.
Container().
From("alpine:latest").
WithExec([]string{
"apk", "add", "figlet",
})
// A Dagger module to say hello to the world!
type Hello struct{}
// Say hello to the world!
func (hello *Hello) Hello(ctx context.Context,
// Change the greeting
// +optional
// +default="hello"
greeting string,
// Change the name
// +optional
// +default="world"
name string,
// Encode the message in giant multi-character letters
// +optional
giant bool,
// Make the message uppercase, and add more exclamation points
// +optional
shout bool,
// Custom container for running the figlet tool
// +optional
figletContainer *dagger.Container,
) (string, error) {
message := fmt.Sprintf("%s, %s!", greeting, name)
if shout {
message = strings.ToUpper(message) + "!!!!!"
}
if giant {
// Run 'figlet' in a container to produce giant letters
ctr := figletContainer
if ctr == nil {
ctr = defaultFigletContainer
}
return ctr.
WithoutEntrypoint(). // clear the entrypoint to make sure 'figlet' is executed
WithExec([]string{"figlet", message}).
Stdout(ctx)
}
return message, nil
}