-
Notifications
You must be signed in to change notification settings - Fork 3
/
person.go
115 lines (92 loc) · 3.26 KB
/
person.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package face
import (
"bytes"
"encoding/json"
"log"
)
type Person struct {
Face
}
func NewPerson(key string) *Person {
if len(key) == 0 {
return nil
}
f := new(Person)
f.client = NewClient(key)
return f
}
func (p *Person) AddFaceByURL(faceUrl, gId, pId, userData, targeFace string) ([]byte, *ErrorResponse) {
data := getUrlByteBuffer(faceUrl)
url := getPersonAddURL(gId, pId, userData, targeFace)
return p.client.Connect("PUT", url, data, true)
}
func (p *Person) AddFaceByPath(path, gId, pId, userData, targeFace string) ([]byte, *ErrorResponse) {
data, err := getFileByteBuffer(path)
if err != nil {
return nil, &ErrorResponse{Err: err}
}
url := getPersonAddURL(gId, pId, userData, targeFace)
return p.client.Connect("PUT", url, data, true)
}
// Create a Person Group with nam and desc
func (p *Person) Create(gId, name, desc string) ([]byte, *ErrorResponse) {
var option InfoParameter
option.Name = name
option.UserData = desc
data, err := json.Marshal(option)
if err != nil {
log.Println("Error happen on json marshal:", err)
return nil, &ErrorResponse{Err: err}
}
url := getPersonGidURL(gId)
return p.client.Connect("PUT", url, bytes.NewBuffer(data), true)
}
// Delte A Person from A PersonGroup
func (p *Person) Delete(gId, pId string) ([]byte, *ErrorResponse) {
data := bytes.NewBuffer([]byte(""))
url := getPersonPidURL(gId, pId)
return p.client.Connect("DELETE", url, data, true)
}
// Delte A Person Face from A PersonGroup/PersonId
func (p *Person) DeleteFace(gId, pId, fId string) ([]byte, *ErrorResponse) {
data := bytes.NewBuffer([]byte(""))
url := getPersonFidURL(gId, pId, fId)
return p.client.Connect("DELETE", url, data, true)
}
// Retrieve a person's information, including registered faces, name and userData.
func (p *Person) Get(gId, pId string) ([]byte, *ErrorResponse) {
url := getPersonPidURL(gId, pId)
data := bytes.NewBuffer([]byte(""))
return p.client.Connect("GET", url, data, true)
}
//Retrieve information about a face (specified by face ID, person ID and its belonging person group ID).
func (p *Person) GetFace(gId, pId, fId string) ([]byte, *ErrorResponse) {
url := getPersonPidURL(gId, pId)
data := bytes.NewBuffer([]byte(""))
return p.client.Connect("GET", url, data, true)
}
//List all people in a person group, and retrieve person information (including person ID, name, user data and registered faces of the person).
func (p *Person) List(gId string) ([]byte, *ErrorResponse) {
url := getPersonGidURL(gId)
data := bytes.NewBuffer([]byte(""))
return p.client.Connect("GET", url, data, true)
}
// Update a person's name or userData field.
func (p *Person) Update(gId, pId, updateName, updateDesc string) ([]byte, *ErrorResponse) {
var option InfoParameter
option.Name = updateName
option.UserData = updateDesc
data, err := json.Marshal(option)
if err != nil {
log.Println("Error happen on json marshal:", err)
return nil, &ErrorResponse{Err: err}
}
url := getPersonPidURL(gId, pId)
return p.client.Connect("PATCH", url, bytes.NewBuffer(data), true)
}
// Update a person face's userData field.
func (p *Person) UpdateFace(gId, pId, fId, updateDesc string) ([]byte, *ErrorResponse) {
data := getUserDataByteBuffer(updateDesc)
url := getPersonFidURL(gId, pId, fId)
return p.client.Connect("PATCH", url, data, true)
}