-
Notifications
You must be signed in to change notification settings - Fork 0
/
file.go
70 lines (53 loc) · 1.18 KB
/
file.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
60
61
62
63
64
65
66
67
68
69
70
// Copyright (c) 2018 Benjamin Borbe All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package file
import (
"context"
"fmt"
"github.com/pkg/errors"
)
type HasPath interface {
Path(ctx context.Context) (string, error)
}
type PathFunc func(ctx context.Context) (string, error)
func (p PathFunc) Path(ctx context.Context) (string, error) {
return p(ctx)
}
type Path string
func (p Path) Path(ctx context.Context) (string, error) {
return p.String(), nil
}
func (p Path) String() string {
return string(p)
}
func (p Path) Validate(ctx context.Context) error {
if p == "" {
return errors.New("Path missing")
}
return nil
}
type User string
func (f User) Validate(ctx context.Context) error {
if f == "" {
return errors.New("User missing")
}
return nil
}
type Group string
func (f Group) Validate(ctx context.Context) error {
if f == "" {
return errors.New("Group missing")
}
return nil
}
type Perm uint32
func (f Perm) Validate(ctx context.Context) error {
if f == 0 {
return errors.New("Perm missing")
}
return nil
}
func (f Perm) String() string {
return fmt.Sprintf("%04o", uint32(f))
}