sig-auth/client/register.go

43 lines
636 B
Go

package client
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"crispbyte.dev/sig-auth/server"
)
func RegisterKey(key string, userId string) error {
request := server.RegisterRequest{
UserId: userId,
Key: key,
}
json_data, _ := json.Marshal(request)
resp, err := http.DefaultClient.Post(
"http://localhost:8080/register",
"application/json",
bytes.NewBuffer(json_data))
if err != nil {
return err
}
defer resp.Body.Close()
out, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
fmt.Println(resp.StatusCode)
fmt.Println(resp.Header)
fmt.Println(string(out[:]))
return nil
}