forked from slsa-framework/example-package
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
56 lines (46 loc) · 1.31 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
// main package
package main
import (
"flag"
"fmt"
"os"
"strings"
"github.com/pborman/uuid"
)
var (
gitVersion string
gitCommit string
gitBranch string
gitTag string
filenameFlags arrayFlags
)
type arrayFlags []string
func (i *arrayFlags) String() string {
return strings.Join(*i, ", ")
}
func (i *arrayFlags) Set(value string) error {
*i = append(*i, value)
return nil
}
func main() {
uuidWithHyphen := uuid.NewRandom()
uuidWithoutHyphen := strings.ReplaceAll(uuidWithHyphen.String(), "-", "")
fmt.Println("GitBranch:", gitBranch)
fmt.Println("GitTag:", gitTag)
fmt.Println("GitVersion:", gitVersion)
fmt.Println("GitCommit:", gitCommit)
fmt.Println("Hello world:", uuidWithoutHyphen)
// To test the container-based builder workflows, this App may also create a file with
// specified contents if provided any filename arguments.
flag.Var(&filenameFlags, "filename", "a filename to write out")
content := flag.String("content", "default", "content to write to the file")
flag.Parse()
for _, filename := range filenameFlags {
fmt.Println("Writing to filename: ", filename)
//nolint:gosec // the builder must be able to read this file
if err := os.WriteFile(filename, []byte(*content), 0o644); err != nil {
fmt.Println("error writing to file: %w", err)
panic(err)
}
}
}