1 Star 0 Fork 0

Cloudy/guac-api

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
guac_users.go 1.34 KB
一键复制 编辑 原始数据 按行查看 历史
package guacamole
import (
"encoding/json"
. "github.com/mdanidl/guac-api/types"
)
func (g *Guac) CreateUser(user *GuacUser) (GuacUser, error) {
ret := GuacUser{}
resp, err := g.Call("POST", "/api/session/data/mysql/users", nil, user)
if err != nil {
return ret, err
}
err = json.Unmarshal(resp, &ret)
return ret, nil
}
func (g *Guac) ReadUser(user *GuacUser) (GuacUser, error) {
ret := GuacUser{}
resp, err := g.Call("GET", "/api/session/data/mysql/users/"+user.Username, nil, nil)
if err != nil {
return GuacUser{}, err
}
err = json.Unmarshal(resp, &ret)
return ret, nil
}
func (g *Guac) UpdateUser(user *GuacUser) error {
_, err := g.Call("PUT", "/api/session/data/mysql/users/"+user.Username, nil, user)
if err != nil {
return err
}
return nil
}
func (g *Guac) DeleteUser(user *GuacUser) error {
_, err := g.Call("DELETE", "/api/session/data/mysql/users/"+user.Username, nil, nil)
if err != nil {
return err
}
return nil
}
func (g *Guac) ListUsers() ([]GuacUser, error) {
ret := []GuacUser{}
marshalledResponse := map[string]GuacUser{}
user_tree, err := g.Call("GET", "/api/session/data/mysql/users", nil, nil)
err = json.Unmarshal(user_tree, &marshalledResponse)
if err != nil {
return []GuacUser{}, err
} else {
for _, datablock := range marshalledResponse {
ret = append(ret, datablock)
}
}
return ret, nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/itcloudy/guac-api.git
git@gitee.com:itcloudy/guac-api.git
itcloudy
guac-api
guac-api
master

搜索帮助