generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 7
/
deployment_key.go
40 lines (33 loc) · 969 Bytes
/
deployment_key.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
package model
import (
"database/sql"
"database/sql/driver"
"encoding"
"errors"
"strings"
)
type DeploymentKey = KeyType[DeploymentPayload, *DeploymentPayload]
var _ interface {
sql.Scanner
driver.Valuer
encoding.TextUnmarshaler
encoding.TextMarshaler
} = (*DeploymentKey)(nil)
func NewDeploymentKey(module string) DeploymentKey { return newKey[DeploymentPayload](module) }
func ParseDeploymentKey(key string) (DeploymentKey, error) {
return parseKey[DeploymentPayload](key)
}
type DeploymentPayload struct {
Module string
}
var _ KeyPayload = (*DeploymentPayload)(nil)
func (d *DeploymentPayload) Kind() string { return "dpl" }
func (d *DeploymentPayload) String() string { return d.Module }
func (d *DeploymentPayload) Parse(parts []string) error {
if len(parts) == 0 {
return errors.New("expected <module> but got empty string")
}
d.Module = strings.Join(parts, "-")
return nil
}
func (d *DeploymentPayload) RandomBytes() int { return 10 }