travis-ci
6 of 6 new or added lines in 3 files covered. (100.0%)
3433 of 3817 relevant lines covered (89.94%)
273.28 hits per line
1 |
package database
|
|
2 |
|
|
3 |
import (
|
|
4 |
"github.com/gansoi/gansoi/ca"
|
|
5 |
) |
|
6 |
|
|
7 |
type (
|
|
8 |
// Object can be embbed in other types for saving to the database and
|
|
9 |
// thereby easily implementing IDSetter.
|
|
10 |
Object struct {
|
|
11 |
ID string `json:"id"` |
|
12 |
} |
|
13 |
) |
|
14 |
|
|
15 |
// SetID will assign a random ID to o if none is set.
|
|
16 |
func (o *Object) SetID() {
|
58 only 427.1 and 427.2 ✔ |
17 |
if o.ID == "" { |
82 only 427.1 and 427.2 ✔ |
18 |
o.ID = ca.RandomString(24)
|
24 only 427.1 and 427.2 ✔ |
19 |
} |
24 only 427.1 and 427.2 ✔ |
20 |
} |
|
21 |
|
|
22 |
// GetID will return the ID of o or an empty string if none is set.
|
|
23 |
func (o *Object) GetID() string { |
166 only 427.1 and 427.2 ✔ |
24 |
return o.ID
|
166 only 427.1 and 427.2 ✔ |
25 |
} |
166 only 427.1 and 427.2 ✔ |