aboutsummaryrefslogtreecommitdiff
path: root/client.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2022-04-16 22:30:27 +0700
committerShulhan <ms@kilabit.info>2022-04-16 22:30:27 +0700
commit0156deaaaa0edbb93cfbf60a8cac99fc17d63a60 (patch)
tree0e373dd81bf402acc78ddc19356f78cb81d5cdb2 /client.go
parent8947cc8b6a9751b3cae3d4d22fdf3ac154f77dfd (diff)
downloadrescached-0156deaaaa0edbb93cfbf60a8cac99fc17d63a60.tar.xz
cmd/resolver: implement sub command to update environment
The env command now accept sub command "update" with argument path to the file or "-" for standard input. The content of file is formatted using JSON, the same as output of "env" command. If the content of file is valid, server will be restarted immediately.
Diffstat (limited to 'client.go')
-rw-r--r--client.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/client.go b/client.go
index bafb16b..524322e 100644
--- a/client.go
+++ b/client.go
@@ -144,3 +144,29 @@ func (cl *Client) Env() (env *Environment, err error) {
}
return env, nil
}
+
+// EnvUpdate update the server environment using new Environment.
+func (cl *Client) EnvUpdate(envIn *Environment) (envOut *Environment, err error) {
+ var (
+ logp = "EnvUpdate"
+ res = libhttp.EndpointResponse{
+ Data: &envOut,
+ }
+
+ resb []byte
+ )
+
+ _, resb, err = cl.PostJSON(apiEnvironment, nil, envIn)
+ if err != nil {
+ return nil, fmt.Errorf("%s: %w", logp, err)
+ }
+
+ err = json.Unmarshal(resb, &res)
+ if err != nil {
+ return nil, fmt.Errorf("%s: %w", logp, err)
+ }
+ if res.Code != http.StatusOK {
+ return nil, fmt.Errorf("%s: %d %s", logp, res.Code, res.Message)
+ }
+ return envOut, nil
+}