-
Notifications
You must be signed in to change notification settings - Fork 5
/
store_fs.go
46 lines (39 loc) · 1020 Bytes
/
store_fs.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
package main
import (
"errors"
"fmt"
"io/ioutil"
"log"
)
type Filesystem struct {
DepFilepath string
JobsPath string
}
func NewFileSystemClient(config *StoreConfig) (*Filesystem, error) {
if config.FsDepPath == "" {
return nil, errors.New("Dependency filepath empty")
}
if config.FsJobsPath == "" {
return nil, errors.New("Jobs filepath empty")
}
return &Filesystem{DepFilepath: config.FsDepPath,
JobsPath: config.FsJobsPath}, nil
}
func (f *Filesystem) GetDependencies() ([]byte, error) {
// NOTE: Add Validate if the file exists
dependencies, err := ioutil.ReadFile(f.DepFilepath)
if err != nil {
log.Fatalf("error reading dependency file: %+v", err)
return nil, err
}
return dependencies, nil
}
func (f *Filesystem) GetJob(job string) ([]byte, error) {
// NOTE: Add Validate if the file exists
nomadJob, err := ioutil.ReadFile(fmt.Sprintf("%s/%s.nomad", f.JobsPath, job))
if err != nil {
log.Fatalf("error reading file: %+v", err)
return nil, err
}
return nomadJob, nil
}