-
Notifications
You must be signed in to change notification settings - Fork 111
/
project.go
44 lines (38 loc) · 1005 Bytes
/
project.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
package storage
import (
"encoding/json"
"github.com/pkg/errors"
)
// Project represents a project definition to be persisted to storage.
type Project struct {
ID string `json:"id"`
Name string `json:"name"`
Type Type `json:"type"`
Status string `json:"status"`
}
// Scan implements pq Scan interface for a Project reference
// so we can pull them out of the database directly as the correct type.
func (p *Project) Scan(src interface{}) error {
if src == nil {
return ErrNotFound
}
source, ok := src.([]byte)
if !ok {
return errors.New("type assertion .([]byte) failed")
}
return json.Unmarshal(source, p)
}
// NewProject is a factory for creating a Project storage object that also does
// validation around what a valid project is in terms of our storage layer.
func NewProject(
id string,
name string,
typeVal Type,
status ProjectRulesStatus) (Project, error) {
return Project{
ID: id,
Name: name,
Type: typeVal,
Status: status.String(),
}, nil
}