blob: b7c829464d121412cf10a9fa9b407913bd57177d [file] [log] [blame]
giolekvab64297c2021-12-13 14:36:32 +04001package main
2
3import (
4 "bytes"
5 "encoding/json"
6 "fmt"
7 "net/http"
8)
9
10type VPNApiClient struct {
11 addr string
12}
13
14type signReq struct {
15 Message []byte `json:"message"`
16}
17
18type signResp struct {
19 Signature []byte `json:"signature"`
20}
21
22func (c *VPNApiClient) Sign(message []byte) ([]byte, error) {
23 var data bytes.Buffer
24 if err := json.NewEncoder(&data).Encode(signReq{message}); err != nil {
25 return nil, err
26 }
27 client := &http.Client{}
28 r, err := client.Post(c.addr+"/api/sign", "application/json", &data)
29 if err != nil {
30 fmt.Println(111111)
31 return nil, err
32 }
33 resp := &signResp{}
34 if err := json.NewDecoder(r.Body).Decode(resp); err != nil {
35 return nil, err
36 }
37 return resp.Signature, nil
38}