File: result.go

package info (click to toggle)
docker.io 18.09.1%2Bdfsg1-7.1%2Bdeb10u3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 66,144 kB
  • sloc: sh: 9,753; makefile: 827; ansic: 239; python: 162; asm: 10
file content (54 lines) | stat: -rw-r--r-- 876 bytes parent folder | download | duplicates (14)
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
package client

import (
	"context"
	"sync"

	"github.com/pkg/errors"
)

type BuildFunc func(context.Context, Client) (*Result, error)

type Result struct {
	mu       sync.Mutex
	Ref      Reference
	Refs     map[string]Reference
	Metadata map[string][]byte
}

func NewResult() *Result {
	return &Result{}
}

func (r *Result) AddMeta(k string, v []byte) {
	r.mu.Lock()
	if r.Metadata == nil {
		r.Metadata = map[string][]byte{}
	}
	r.Metadata[k] = v
	r.mu.Unlock()
}

func (r *Result) AddRef(k string, ref Reference) {
	r.mu.Lock()
	if r.Refs == nil {
		r.Refs = map[string]Reference{}
	}
	r.Refs[k] = ref
	r.mu.Unlock()
}

func (r *Result) SetRef(ref Reference) {
	r.Ref = ref
}

func (r *Result) SingleRef() (Reference, error) {
	r.mu.Lock()
	defer r.mu.Unlock()

	if r.Refs != nil && r.Ref == nil {
		return nil, errors.Errorf("invalid map result")
	}

	return r.Ref, nil
}