-
Notifications
You must be signed in to change notification settings - Fork 390
/
service.go
59 lines (46 loc) · 1.19 KB
/
service.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
// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.
package crash
import (
"fmt"
"os"
"path"
"time"
"github.com/zeebo/errs"
"storj.io/common/storj"
)
// Config contains configurable values for crash collect service.
type Config struct {
StoringDir string `help:"directory to store crash reports" default:""`
}
// Error is a default error type for crash collect Service.
var Error = errs.Class("crashes service")
// Service exposes all crash-collect business logic.
//
// architecture: service
type Service struct {
config Config
}
// NewService is an constructor for Service.
func NewService(config Config) *Service {
return &Service{
config: config,
}
}
// Report receives report from crash-report client and saves it into .gz file.
func (s *Service) Report(nodeID storj.NodeID, gzippedPanic []byte) error {
now := time.Now().UTC()
filename := fmt.Sprintf("%s-%s.gz", nodeID.String(), now.Format(time.RFC3339))
f, err := os.Create(path.Join(s.config.StoringDir, filename))
if err != nil {
return Error.Wrap(err)
}
defer func() {
err = errs.Combine(err, f.Close())
}()
_, err = f.Write(gzippedPanic)
if err != nil {
return Error.Wrap(err)
}
return nil
}