This repository has been archived by the owner on Aug 30, 2022. It is now read-only.
/
project.go
54 lines (43 loc) · 1.63 KB
/
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
45
46
47
48
49
50
51
52
53
54
/*
* +===============================================
* | Author: Parham Alvani <parham.alvani@gmail.com>
* |
* | Creation Date: 18-11-2017
* |
* | File Name: project.go
* +===============================================
*/
package model
import (
"math/rand"
"time"
"github.com/I1820/I1820/internal/runner"
)
// Project represents structure of I1820 platform projects
// The project is a virtual entity that collects things together
// under one name and eases their management,
// like an Agricultural project that manages your farm and its smart things.
type Project struct {
ID string `json:"id" bson:"id"` // Project unique identifier
Name string `json:"name" bson:"name"` // project human readable name
Runner runner.Runner `json:"runner" bson:"runner"` // information about project docker
Description string `json:"description" bson:"description"` // project description
Perimeter struct { // operational perimeter
Type string `json:"type" bson:"type"` // GeoJSON type eg. "Polygon"
// coordinates eg. [ [ [ 0 , 0 ] , [ 3 , 6 ] , [ 6 , 1 ] , [ 0 , 0 ] ] ]
Coordinates [][][]float64 `json:"coordinates" bson:"coordinates"`
} `json:"perimeter" bson:"perimeter"`
}
// NewProjectID generates a random string as a project identification.
func NewProjectID() string {
rand.Seed(time.Now().UnixNano())
// Length is a random key length
const Length = 6
const source = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"
// Key generates a random key from the source
b := make([]byte, Length)
for i := range b {
b[i] = source[rand.Intn(len(source))]
}
return string(b)
}