Move code for key registration
This commit is contained in:
parent
cab114fae3
commit
30cdf2c7e7
2 changed files with 44 additions and 23 deletions
24
main.go
24
main.go
|
@ -130,31 +130,9 @@ func registerKey(keyFile string, userId string) {
|
|||
|
||||
keyText := string(keyBytes)
|
||||
|
||||
request := server.RegisterRequest{
|
||||
UserId: userId,
|
||||
Key: keyText,
|
||||
}
|
||||
|
||||
json_data, _ := json.Marshal(request)
|
||||
|
||||
resp, err := http.DefaultClient.Post(
|
||||
"http://localhost:8080/register",
|
||||
"application/json",
|
||||
bytes.NewBuffer(json_data))
|
||||
err = client.RegisterKey(keyText, userId)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
out, err := io.ReadAll(resp.Body)
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Println(resp.StatusCode)
|
||||
fmt.Println(resp.Header)
|
||||
fmt.Println(string(out[:]))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue