-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.go
55 lines (49 loc) · 1.23 KB
/
user.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
package harper
type User struct {
Record
Active bool `json:"active"`
Role Role `json:"role"`
Username string `json:"username"`
}
func (c *Client) AddUser(username, password, roleID string, active bool) error {
return c.opRequest(operation{
Operation: OP_ADD_USER,
Role: roleID,
Username: username,
Password: password,
Active: &active,
}, nil)
}
func (c *Client) AlterUser(username, password, roleID string, active bool) error {
return c.opRequest(operation{
Operation: OP_ALTER_USER,
Role: roleID,
Username: username,
Password: password,
Active: &active,
}, nil)
}
// DropUser deletes a user.
// Note: this operation is idempotent, it will not throw an error
// if the user doesn't exist
func (c *Client) DropUser(username string) error {
return c.opRequest(operation{
Operation: OP_DROP_USER,
Username: username,
}, nil)
}
// UserInfo returns the current user executing this operation
func (c *Client) UserInfo() (User, error) {
var user User
err := c.opRequest(operation{
Operation: OP_USER_INFO,
}, &user)
return user, err
}
func (c *Client) ListUsers() ([]User, error) {
var users []User
err := c.opRequest(operation{
Operation: OP_LIST_USERS,
}, &users)
return users, err
}