/
contacts.go
36 lines (29 loc) · 1013 Bytes
/
contacts.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
package compliance
import (
"net/http"
)
type ContactService service
func (srv ContactService) List() ([]Contact, error) {
contacts := []Contact{}
err := srv.client.Do(http.MethodGet, "/api/v1/contacts", nil, &contacts)
return contacts, err
}
func (srv ContactService) Get(contactID string) (Contact, error) {
contact := Contact{}
err := srv.client.Do(http.MethodGet, "/api/v1/contacts/"+contactID, nil, &contact)
return contact, err
}
func (srv ContactService) Create(create Contact) (Contact, error) {
contact := Contact{}
err := srv.client.Do(http.MethodPost, "/api/v1/contacts", create, &contact)
return contact, err
}
func (srv ContactService) Update(contactID string, update Contact) (Contact, error) {
contact := Contact{}
err := srv.client.Do(http.MethodPut, "/api/v1/contacts/"+contactID, update, &contact)
return contact, err
}
func (srv ContactService) Delete(contactID string) error {
err := srv.client.Do(http.MethodDelete, "/api/v1/contacts/"+contactID, nil, nil)
return err
}