-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
output.go
53 lines (44 loc) · 1.01 KB
/
output.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
package topology // import "github.com/nathanaelle/wireguard-topology"
import (
"fmt"
"io"
"os"
"path/filepath"
)
type (
Output interface {
AddFolder(name ...string) error
AddEntry(name ...string) (io.WriteCloser, error)
}
tgzOutput struct {
}
tgzEntry struct {
}
dirOutput struct {
rootDir string
}
)
var _ Output = &dirOutput{}
func NewDirOutput(rootDir string) Output {
return &dirOutput{
rootDir: rootDir,
}
}
func (do *dirOutput) AddFolder(name ...string) error {
destDir := filepath.Join(do.rootDir, filepath.Join(name...))
if err := os.MkdirAll(destDir, 0700); err != nil {
return fmt.Errorf("cant create %q : %v", destDir, err)
}
return nil
}
func (do *dirOutput) AddEntry(name ...string) (io.WriteCloser, error) {
filename := filepath.Join(do.rootDir, filepath.Join(name...))
file, err := os.Create(filename)
if err != nil {
return nil, fmt.Errorf("can't create file %q : %v", filename, err)
}
return file, nil
}
//func NewTgzOutput(file string) Output {
// return &tgzOutput{}
//}