func (c *FusionAuthClient) CreateEntityType(entityTypeId string, request EntityTypeRequest) (*EntityTypeResponse, *Errors, error) {
	var resp EntityTypeResponse
	var errors Errors
	restClient := c.Start(&resp, &errors)
	err := restClient.WithUri("/api/entity/type").
		WithUriSegment(entityTypeId).
		WithJSONBody(request).
		WithMethod(http.MethodPost).
		Do()
	if restClient.ErrorRef == nil {
		return &resp, nil, err
	}
	return &resp, &errors, err
}
CreateEntityType
Creates a Entity Type. You can optionally specify an Id for the Entity Type, if not provided one will be generated.
string entityTypeId (Optional) The Id for the Entity Type. If not provided a secure random UUID will be generated.
EntityTypeRequest request The request object that contains all of the information used to create the Entity Type.
package fusionauth
import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
	"net/http/httputil"
	"net/url"
	"path"
	"strconv"
	"strings"
	"time"
)
func NewClient(httpClient *http.Client, baseURL *url.URL, apiKey string) *FusionAuthClient {
	if httpClient == nil {
		httpClient = &http.Client{
			Timeout: 5 * time.Minute,
		}
	}
	c := &FusionAuthClient{
		HTTPClient: httpClient,
		BaseURL:    baseURL,
		APIKey:     apiKey,
	}
	return c
}
func (c *FusionAuthClient) SetTenantId(tenantId string) {
	c.TenantId = tenantId
}
type FusionAuthClient struct {
	HTTPClient *http.Client
	BaseURL    *url.URL
	APIKey     string
	Debug      bool
	TenantId   string
}
type restClient struct {
	Body        io.Reader
	Debug       bool
	ErrorRef    interface{}
	Headers     map[string]string
	HTTPClient  *http.Client
	Method      string
	ResponseRef interface{}
	Uri         *url.URL
}
func (c *FusionAuthClient) Start(responseRef interface{}, errorRef interface{}) *restClient {
	return c.StartAnonymous(responseRef, errorRef).WithAuthorization(c.APIKey)
}
func (c *FusionAuthClient) StartAnonymous(responseRef interface{}, errorRef interface{}) *restClient {
	rc := &restClient{
		Debug:       c.Debug,
		ErrorRef:    errorRef,
		Headers:     make(map[string]string),
		HTTPClient:  c.HTTPClient,
		ResponseRef: responseRef,
	}
	rc.Uri, _ = url.Parse(c.BaseURL.String())
	if c.TenantId != "" {
		rc.WithHeader("X-FusionAuth-TenantId", c.TenantId)
	}
	rc.WithHeader("Content-Type", "text/plain")
	rc.WithHeader("Accept", "application/json")
	return rc
}
func (rc *restClient) Do() error {
	req, err := http.NewRequest(rc.Method, rc.Uri.String(), rc.Body)
	if err != nil {
		return err
	}
	for key, val := range rc.Headers {
		req.Header.Set(key, val)
	}
	resp, err := rc.HTTPClient.Do(req)
	if err != nil {
		return err
	}
	defer resp.Body.Close()
	if rc.Debug {
		responseDump, _ := httputil.DumpResponse(resp, true)
		fmt.Println(string(responseDump))
	}
	if resp.StatusCode < 200 || resp.StatusCode > 299 {
		if err = json.NewDecoder(resp.Body).Decode(rc.ErrorRef); err == io.EOF {
			err = nil
		}
	} else {
		rc.ErrorRef = nil
		if _, ok := rc.ResponseRef.(*BaseHTTPResponse); !ok {
			err = json.NewDecoder(resp.Body).Decode(rc.ResponseRef)
		}
	}
	rc.ResponseRef.(StatusAble).SetStatus(resp.StatusCode)
	return err
}
func (rc *restClient) WithAuthorization(key string) *restClient {
	if key != "" {
		rc.WithHeader("Authorization", key)
	}
	return rc
}
func (rc *restClient) WithFormData(formBody url.Values) *restClient {
	rc.WithHeader("Content-Type", "application/x-www-form-urlencoded")
	rc.Body = strings.NewReader(formBody.Encode())
	return rc
}
func (rc *restClient) WithHeader(key string, value string) *restClient {
	rc.Headers[key] = value
	return rc
}
func (rc *restClient) WithJSONBody(body interface{}) *restClient {
	rc.WithHeader("Content-Type", "application/json")
	buf := new(bytes.Buffer)
	json.NewEncoder(buf).Encode(body)
	rc.Body = buf
	return rc
}
func (rc *restClient) WithMethod(method string) *restClient {
	rc.Method = method
	return rc
}
func (rc *restClient) WithParameter(key string, value interface{}) *restClient {
	q := rc.Uri.Query()
	if x, ok := value.([]string); ok {
		for _, i := range x {
			q.Add(key, i)
		}
	} else {
		q.Add(key, fmt.Sprintf("%v", value))
	}
	rc.Uri.RawQuery = q.Encode()
	return rc
}
func (rc *restClient) WithUri(uri string) *restClient {
	rc.Uri.Path = path.Join(rc.Uri.Path, uri)
	return rc
}
func (rc *restClient) WithUriSegment(segment string) *restClient {
	if segment != "" {
		rc.Uri.Path = path.Join(rc.Uri.Path, "/"+segment)
	}
	return rc
}
func (c *FusionAuthClient) ActionUser(request ActionRequest) (*ActionResponse, *Errors, error) {
	var resp ActionResponse
	var errors Errors
	restClient := c.Start(&resp, &errors)
	err := restClient.WithUri("/api/user/action").
		WithJSONBody(request).
		WithMethod(http.MethodPost).
		Do()
	if restClient.ErrorRef == nil {
		return &resp, nil, err
	}
	return &resp, &errors, err
}
func (c *FusionAuthClient) ActivateReactor(request ReactorRequest) (*BaseHTTPResponse, *Errors, error) {
	var resp BaseHTTPResponse
	var errors Errors
	restClient := c.Start(&resp, &errors)
	err := restClient.WithUri("/api/reactor").
		WithJSONBody(request).
		WithMethod(http.MethodPost).
		Do()
	if restClient.ErrorRef == nil {
		return &resp, nil, err
	}
	return &resp, &errors, err
}
func (c *FusionAuthClient) AddUserToFamily(familyId string, request FamilyRequest) (*FamilyResponse, *Errors, error) {
	var resp FamilyResponse
	var errors Errors
	restClient := c.Start(&resp, &errors)
	err := restClient.WithUri("/api/user/family").
		WithUriSegment(familyId).
		WithJSONBody(request).
		WithMethod(http.MethodPut).
		Do()
	if restClient.ErrorRef == nil {
		return &resp, nil, err
	}
	return &resp, &errors, err
}
func (c *FusionAuthClient) CancelAction(actionId string, request ActionRequest) (*ActionResponse, *Errors, error) {
	var resp ActionResponse
	var errors Errors
	restClient := c.Start(&resp, &errors)
	err := restClient.WithUri("/api/user/action").
		WithUriSegment(actionId).
		WithJSONBody(request).
		WithMethod(http.MethodDelete).
		Do()
	if restClient.ErrorRef == nil {
		return &resp, nil, err
	}
	return &resp, &errors, err
}
func (c *FusionAuthClient) ChangePassword(changePasswordId string, request ChangePasswordRequest) (*ChangePasswordResponse, *Errors, error) {
	var resp ChangePasswordResponse
	var errors Errors
	restClient := c.StartAnonymous(&resp, &errors)
	err := restClient.WithUri("/api/user/change-password").
		WithUriSegment(changePasswordId).
		WithJSONBody(request).
		WithMethod(http.MethodPost).
		Do()
	if restClient.ErrorRef == nil {
		return &resp, nil, err
	}
	return &resp, &errors, err
}
func (c *FusionAuthClient) ChangePasswordByIdentity(request ChangePasswordRequest) (*BaseHTTPResponse, *Errors, error) {
	var resp BaseHTTPResponse
	var errors Errors
	restClient := c.Start(&resp, &errors)
	err := restClient.WithUri("/api/user/change-password").
		WithJSONBody(request).
		WithMethod(http.MethodPost).
		Do()
	if restClient.ErrorRef == nil {
		return &resp, nil, err
	}
	return &resp, &errors, err
}
func (c *FusionAuthClient) CommentOnUser(request UserCommentRequest) (*BaseHTTPResponse, *Errors, error) {
	var resp BaseHTTPResponse
	var errors Errors
	restClient := c.Start(&resp, &errors)
	err := restClient.WithUri("/api/user/comment").
		WithJSONBody(request).
		WithMethod(http.MethodPost).
		Do()
	if restClient.ErrorRef == nil {
		return &resp, nil, err
	}
	return &resp, &errors, err
}
func (c *FusionAuthClient) CreateAPIKey(keyId string, request APIKeyRequest) (*APIKeyResponse, *Errors, error) {
	var resp APIKeyResponse
	var errors Errors
	restClient := c.Start(&resp, &errors)
	err := restClient.WithUri("/api/api-key").
		WithUriSegment(keyId).
		WithJSONBody(request).
		WithMethod(http.MethodPost).
		Do()
	if restClient.ErrorRef == nil {
		return &resp, nil, err
	}
	return &resp, &errors, err
}
func (c *FusionAuthClient) CreateApplication(applicationId string, request ApplicationRequest) (*ApplicationResponse, *Errors, error) {
	var resp ApplicationResponse
	var errors Errors
	restClient := c.Start(&resp, &errors)
	err := restClient.WithUri("/api/application").
		WithUriSegment(applicationId).
		WithJSONBody(request).
		WithMethod(http.MethodPost).
		Do()
	if restClient.ErrorRef == nil {
		return &resp, nil, err
	}
	return &resp, &errors, err
}
func (c *FusionAuthClient) CreateApplicationRole(applicationId string, roleId string, request ApplicationRequest) (*ApplicationResponse, *Errors, error) {
	var resp ApplicationResponse
	var errors Errors
	restClient := c.Start(&resp, &errors)
	err := restClient.WithUri("/api/application").
		WithUriSegment(applicationId).
		WithUriSegment("role").
		WithUriSegment(roleId).
		WithJSONBody(request).
		WithMethod(http.MethodPost).
		Do()
	if restClient.ErrorRef == nil {
		return &resp, nil, err
	}
	return &resp, &errors, err
}
func (c *FusionAuthClient) CreateAuditLog(request AuditLogRequest) (*AuditLogResponse, *Errors, error) {
	var resp AuditLogResponse
	var errors Errors
	restClient := c.Start(&resp, &errors)
	err := restClient.WithUri("/api/system/audit-log").
		WithJSONBody(request).
		WithMethod(http.MethodPost).
		Do()
	if restClient.ErrorRef == nil {
		return &resp, nil, err
	}
	return &resp, &errors, err
}
func (c *FusionAuthClient) CreateConnector(connectorId string, request ConnectorRequest) (*ConnectorResponse, *Errors, error) {
	var resp ConnectorResponse
	var errors Errors
	restClient := c.Start(&resp, &errors)
	err := restClient.WithUri("/api/connector").
		WithUriSegment(connectorId).
		WithJSONBody(request).
		WithMethod(http.MethodPost).
		Do()
	if restClient.ErrorRef == nil {
		return &resp, nil, err
	}
	return &resp, &errors, err
}
func (c *FusionAuthClient) CreateConsent(consentId string, request ConsentRequest) (*ConsentResponse, *Errors, error) {
	var resp ConsentResponse
	var errors Errors
	restClient := c.Start(&resp, &errors)
	err := restClient.WithUri("/api/consent").
		WithUriSegment(consentId).
		WithJSONBody(request).
		WithMethod(http.MethodPost).
		Do()
	if restClient.ErrorRef == nil {
		return &resp, nil, err
	}
	return &resp, &errors, err
}
func (c *FusionAuthClient) CreateEmailTemplate(emailTemplateId string, request EmailTemplateRequest) (*EmailTemplateResponse, *Errors, error) {
	var resp EmailTemplateResponse
	var errors Errors
	restClient := c.Start(&resp, &errors)
	err := restClient.WithUri("/api/email/template").
		WithUriSegment(emailTemplateId).
		WithJSONBody(request).
		WithMethod(http.MethodPost).
		Do()
	if restClient.ErrorRef == nil {
		return &resp, nil, err
	}
	return &resp, &errors, err
}
func (c *FusionAuthClient) CreateEntity(entityId string, request EntityRequest) (*EntityResponse, *Errors, error) {
	var resp EntityResponse
	var errors Errors
	restClient := c.Start(&resp, &errors)
	err := restClient.WithUri("/api/entity").
		WithUriSegment(entityId).
		WithJSONBody(request).
		WithMethod(http.MethodPost).
		Do()
	if restClient.ErrorRef == nil {
		return &resp, nil, err
	}
	return &resp, &errors, err
}