Files
Олег Бородин 25365aef77 init import
2026-05-24 11:02:51 +02:00

72 lines
1.5 KiB
Go

package accntcli
import (
"context"
"encoding/json"
"errors"
"mbase/app/accoper"
"mbase/app/handler"
)
func (cli *Client) CreateGrantByAccountID(ctx context.Context, host string, accountID, right, pattern string) (string, error) {
var err error
var res string
params := accoper.CreateGrantParams{
AccountID: accountID,
Right: right,
Pattern: pattern,
}
reqdata, err := json.Marshal(params)
if err != nil {
return res, err
}
respdata, err := cli.doHTTPCall(ctx, host, "grant", "create", reqdata)
if err != nil {
return res, err
}
response := handler.NewResponse[accoper.CreateGrantResult]()
err = json.Unmarshal(respdata, response)
if err != nil {
return res, err
}
if response.Error {
err = errors.New(response.Message)
return res, err
}
res = response.Result.GrantID
return res, err
}
func (cli *Client) CreateGrantByUsername(ctx context.Context, host, username string, right string, pattern string) (string, error) {
var err error
var res string
params := accoper.CreateGrantParams{
Username: username,
Right: right,
Pattern: pattern,
}
reqdata, err := json.Marshal(params)
if err != nil {
return res, err
}
respdata, err := cli.doHTTPCall(ctx, host, "grant", "create", reqdata)
if err != nil {
return res, err
}
response := handler.NewResponse[accoper.CreateGrantResult]()
err = json.Unmarshal(respdata, response)
if err != nil {
return res, err
}
if response.Error {
err = errors.New(response.Message)
return res, err
}
res = response.Result.GrantID
return res, err
}