Debian Codegraph @

recorder/recorder.go

raw
1 /*
2 Copyright The containerd Authors.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17 // Package recorder provides log recorder
18 package recorder
19
20 import (
21 "encoding/json"
22 "io"
23 "sync"
24 )
25
26 type Entry struct {
27 Path string `json:"path"`
28 ManifestDigest string `json:"manifestDigest,omitempty"`
29 LayerIndex *int `json:"layerIndex,omitempty"`
30 }
31
32 func New(w io.Writer) *Recorder {
33 return &Recorder{
34 enc: json.NewEncoder(w),
35 }
36 }
37
38 // Recorder is thread-safe.
39 type Recorder struct {
40 enc *json.Encoder
41 mu sync.Mutex
42 }
43
44 func (ll *Recorder) Record(e *Entry) error {
45 ll.mu.Lock()
46 defer ll.mu.Unlock()
47 return ll.enc.Encode(e)
48 }