generated from dkoshkin/golang-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
54 lines (43 loc) · 1.14 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
// Copyright 2023 Dimitri Koshkin. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
package main
import (
"context"
"fmt"
"os"
"github.com/sethvargo/go-githubactions"
"github.com/dkoshkin/status-writer-action/pkg/remote"
"github.com/dkoshkin/status-writer-action/pkg/version"
)
func run() error {
ctx := context.Background()
action := githubactions.New()
cfg, err := remote.NewFromInputs(action)
if err != nil {
//nolint:wrapcheck // we don't want to wrap this error
return err
}
var writer remote.Writer
switch cfg.Backend {
case remote.BackendInfluxDB:
writer = remote.NewInfluxDBWriter(cfg.InfluxDB)
case remote.BackendGoogleSheets:
writer, err = remote.NewGoogleSheetsWriter(ctx, cfg.GoogleSheets)
if err != nil {
return fmt.Errorf("error creating Google Sheets writer: %w", err)
}
}
//nolint:wrapcheck // we don't want to wrap this error
return writer.Write(ctx, cfg.Data)
}
func main() {
if len(os.Args) > 1 &&
(os.Args[1] == "version" || os.Args[1] == "-v" || os.Args[1] == "--version") {
fmt.Println(version.Print())
os.Exit(0)
}
err := run()
if err != nil {
githubactions.Fatalf("%v", err)
}
}