feat(client): add settings clients
This commit is contained in:
parent
76cf1274af
commit
83436eac6a
5 changed files with 56 additions and 2 deletions
|
@ -1,9 +1,12 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/ihexxa/quickshare/src/db/sitestore"
|
||||
"github.com/ihexxa/quickshare/src/handlers/settings"
|
||||
"github.com/parnurzeal/gorequest"
|
||||
)
|
||||
|
||||
|
@ -28,3 +31,26 @@ func (cl *SettingsClient) Health() (*http.Response, string, []error) {
|
|||
return cl.r.Options(cl.url("/v1/settings/health")).
|
||||
End()
|
||||
}
|
||||
|
||||
func (cl *SettingsClient) GetClientCfg(token *http.Cookie) (*http.Response, *settings.ClientCfgMsg, []error) {
|
||||
resp, body, errs := cl.r.Get(cl.url("/v1/settings/client")).
|
||||
AddCookie(token).
|
||||
End()
|
||||
|
||||
mResp := &settings.ClientCfgMsg{}
|
||||
err := json.Unmarshal([]byte(body), mResp)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
return nil, nil, errs
|
||||
}
|
||||
return resp, mResp, nil
|
||||
}
|
||||
|
||||
func (cl *SettingsClient) SetClientCfg(cfg *sitestore.ClientConfig, token *http.Cookie) (*http.Response, string, []error) {
|
||||
return cl.r.Patch(cl.url("/v1/settings/client")).
|
||||
AddCookie(token).
|
||||
Send(&settings.ClientCfgMsg{
|
||||
ClientCfg: cfg,
|
||||
}).
|
||||
End()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue