forked from jumpjumpbean/go-activiti-rest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusers.go
88 lines (68 loc) · 1.89 KB
/
users.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
package activiti
import (
"fmt"
)
// GetUser retrieves user by ID
// Endpoint: GET identity/users/{userId}
func (c *ActClient) GetUser(uid string) (*ActUser, error) {
user := &ActUser{}
req, err := c.NewRequest("GET", fmt.Sprintf("%s%s%s", c.BaseURL, "/identity/users/", uid), nil)
if err != nil {
return user, err
}
if err = c.SendWithBasicAuth(req, user); err != nil {
return user, err
}
return user, nil
}
// GetUsers retrieves all users
// Endpoint: GET identity/users
func (c *ActClient) GetUsers() (*ActUsers, error) {
users := &ActUsers{}
req, err := c.NewRequest("GET", fmt.Sprintf("%s%s", c.BaseURL, "/identity/users"), nil)
if err != nil {
return users, err
}
if err = c.SendWithBasicAuth(req, users); err != nil {
return users, err
}
return users, nil
}
// CreateUser creates a user in activiti
// Endpoint: POST identity/users
func (c *ActClient) CreateUser(u ActUser) (*ActUser, error) {
user := &ActUser{}
req, err := c.NewRequest("POST", fmt.Sprintf("%s%s", c.BaseURL, "/identity/users"), u)
if err != nil {
return user, err
}
if err = c.SendWithBasicAuth(req, user); err != nil {
return user, err
}
return user, nil
}
// UpdateUser updates a user in activiti
// Endpoint: PUT identity/users/{userId}
func (c *ActClient) UpdateUser(u ActUser) (*ActUser, error) {
user := &ActUser{}
req, err := c.NewRequest("PUT", fmt.Sprintf("%s%s%s", c.BaseURL, "/identity/users/", u.ID), u)
if err != nil {
return user, err
}
if err = c.SendWithBasicAuth(req, user); err != nil {
return user, err
}
return user, nil
}
// DeleteUser deletes a user in activiti
// Endpoint: DELETE identity/users/{userId}
func (c *ActClient) DeleteUser(uid string) error {
req, err := c.NewRequest("DELETE", fmt.Sprintf("%s%s%s", c.BaseURL, "/identity/users/", uid), nil)
if err != nil {
return err
}
if err = c.SendWithBasicAuth(req, nil); err != nil {
return err
}
return nil
}