-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #125 from formalco/add_user_async
Add user async
- Loading branch information
Showing
23 changed files
with
176 additions
and
1,963 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,14 @@ | ||
package api | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"time" | ||
"github.com/formalco/go-sdk/sdk" | ||
) | ||
|
||
type Client struct { | ||
HostURL string | ||
HTTPClient *http.Client | ||
APIKey string | ||
type GrpcClient struct { | ||
ReturnSensitiveValue bool | ||
Sdk *sdk.FormalSDK | ||
} | ||
|
||
const FORMAL_HOST_URL string = "https://api.formalcloud.net" | ||
|
||
func NewClient(apiKey string, returnSensitiveValue bool) (*Client, error) { | ||
c := Client{ | ||
HTTPClient: &http.Client{Timeout: 100 * time.Second}, | ||
APIKey: apiKey, | ||
HostURL: FORMAL_HOST_URL, | ||
ReturnSensitiveValue: returnSensitiveValue, | ||
} | ||
|
||
return &c, nil | ||
} | ||
|
||
func (c *Client) doRequest(req *http.Request) ([]byte, error) { | ||
if c.APIKey == "" { | ||
return nil, errors.New("client was not initialized with an api key") | ||
} | ||
req.Header.Add("X-Api-Key", c.APIKey) | ||
|
||
res, err := c.HTTPClient.Do(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer res.Body.Close() | ||
|
||
body, err := io.ReadAll(res.Body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if res.StatusCode != http.StatusOK { | ||
return nil, fmt.Errorf("status: %d, body: %s", res.StatusCode, body) | ||
} | ||
|
||
return body, err | ||
func NewClient(apiKey string, returnSensitiveValue bool) *GrpcClient { | ||
return &GrpcClient{Sdk: sdk.New(apiKey), ReturnSensitiveValue: returnSensitiveValue} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.