response

package
v0.33.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AlreadyExistsError

func AlreadyExistsError() events.APIGatewayProxyResponse

func BadRequestError

func BadRequestError(message string) events.APIGatewayProxyResponse

func BuildNextURL

func BuildNextURL(r *http.Request, nextParams map[string]string, baseRequest url.URL) url.URL

BuildNextURL merges the next parameters of pagination into the request parameters and returns an API URL.

func ClientBadRequestError

func ClientBadRequestError(message string) events.APIGatewayProxyResponse

func ClientErrorWithResponse

func ClientErrorWithResponse(message string) events.APIGatewayProxyResponse

func ConflictError

func ConflictError(message string) events.APIGatewayProxyResponse

func CreateAPIGatewayErrorResponse

func CreateAPIGatewayErrorResponse(responseCode int,
	errResp ErrorResponse) events.APIGatewayProxyResponse

CreateAPIGatewayErrorResponse is a helper function to create and return a valid error response message for the API

func CreateAPIGatewayJSONResponse

func CreateAPIGatewayJSONResponse(status int, response interface{}) events.APIGatewayProxyResponse

CreateAPIGatewayJSONResponse - Create a JSON response

func CreateAPIGatewayResponse

func CreateAPIGatewayResponse(status int, body string) events.APIGatewayProxyResponse

CreateAPIGatewayResponse is a helper function to create and return a valid response for an API Gateway

func CreateMultiValueHeaderAPIErrorResponse

func CreateMultiValueHeaderAPIErrorResponse(status int, errorCode string, message string) events.APIGatewayProxyResponse

CreateMultiValueHeaderAPIErrorResponse - Creates an error response with mulit-value headers

func CreateMultiValueHeaderAPIResponse

func CreateMultiValueHeaderAPIResponse(status int, body string) events.APIGatewayProxyResponse

CreateMultiValueHeaderAPIResponse - creates a response with multi-value headers

func CreateMultiValueHeaderJSONResponse

func CreateMultiValueHeaderJSONResponse(status int, response interface{}) events.APIGatewayProxyResponse

CreateMultiValueHeaderJSONResponse - Creates a response with JSON in it with multi-value headers

func NotFoundError

func NotFoundError() events.APIGatewayProxyResponse

func RequestValidationError

func RequestValidationError(message string) events.APIGatewayProxyResponse

func ServerError

func ServerError() events.APIGatewayProxyResponse

func ServerErrorWithResponse

func ServerErrorWithResponse(message string) events.APIGatewayProxyResponse

func ServiceUnavailableError

func ServiceUnavailableError(message string) events.APIGatewayProxyResponse

func UnauthorizedError

func UnauthorizedError() events.APIGatewayProxyResponse

func UnsupportedMethodError

func UnsupportedMethodError(method string) events.APIGatewayProxyResponse

func WriteAPIErrorResponse

func WriteAPIErrorResponse(w http.ResponseWriter, responseCode int,
	errCode string, errMessage string)

WriteAPIErrorResponse - Writes the error response out to the provided ResponseWriter

func WriteAPIResponse

func WriteAPIResponse(w http.ResponseWriter, status int, body string)

WriteAPIResponse - Writes the response out to the provided ResponseWriter

func WriteAlreadyExistsError

func WriteAlreadyExistsError(w http.ResponseWriter)

WriteAlreadyExistsError - Writes the already exists error.

func WriteBadRequestError

func WriteBadRequestError(w http.ResponseWriter, message string)

WriteBadRequestError - Writes a request validate error with the given message.

func WriteConflictError

func WriteConflictError(w http.ResponseWriter, message string)

WriteConflictError - Writes a request validate error with the given message.

func WriteNotFoundError

func WriteNotFoundError(w http.ResponseWriter)

WriteNotFoundError - Writes a request validate error with the given message.

func WriteRequestValidationError

func WriteRequestValidationError(w http.ResponseWriter, message string)

WriteRequestValidationError - Writes a request validate error with the given message.

func WriteServerError

func WriteServerError(w http.ResponseWriter)

WriteServerError - Writes a server error with the specific message.

func WriteServerErrorWithResponse

func WriteServerErrorWithResponse(w http.ResponseWriter, message string)

WriteServerErrorWithResponse - Writes a server error with the specific message.

func WriteServiceUnavailableError

func WriteServiceUnavailableError(w http.ResponseWriter, message string)

WriteServiceUnavailableError - Writes a request validate error with the given message.

Types

type AccountResponse

type AccountResponse struct {
	ID                  string                 `json:"id"`
	AccountStatus       db.AccountStatus       `json:"accountStatus"`
	LastModifiedOn      int64                  `json:"lastModifiedOn"`
	CreatedOn           int64                  `json:"createdOn"`
	AdminRoleArn        string                 `json:"adminRoleArn"`        // Assumed by the master account, to manage this user account
	PrincipalRoleArn    string                 `json:"principalRoleArn"`    // Assumed by principal users
	PrincipalPolicyHash string                 `json:"principalPolicyHash"` // The policy used by the PrincipalRoleArn
	Metadata            map[string]interface{} `json:"metadata"`
}

AccountResponse is the serialized JSON Response for an account to be returned for APIs

{
	"id": "123",
	"status": "Active",
	"lastModifiedOn": 56789,
	"createOn": 12345,
	"adminRoleArn": " arn:aws:iam::1234567890:role/adminRole
}

Converting from a db.Account can be done via type casting:

dbAccount := db.Account{...}
accountRes := response.AccountResponse(dbAccount)

type ErrorBase

type ErrorBase struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

ErrorBase is the base structure for the ErrorResponse containing the Error Code and Message

{
	"code": "ServerError",
	"message": "Error Calculating"
}

type ErrorResponse

type ErrorResponse struct {
	Error ErrorBase `json:"error"`
}

ErrorResponse is the structured JSON Response for an Error to be returned for APIs

{
	"error": {
		"code": "ServerError",
		"message": "Error Calculating"
	}
}

func CreateErrorResponse

func CreateErrorResponse(code string, message string) ErrorResponse

CreateErrorResponse creates and returns a formatted JSON string of the structured ErrorResponse

type LeaseAuthResponse

type LeaseAuthResponse struct {
	AccessKeyID     string `json:"accessKeyId"`
	SecretAccessKey string `json:"secretAccessKey"`
	SessionToken    string `json:"sessionToken"`
	ConsoleURL      string `json:"consoleUrl"`
}

LeaseAuthResponse is the structured JSON Response for an Lease to be returned for APIs

{
	"accessKeyId": "AKIAI44QH8DHBEXAMPLE",
	"secretAccessKey": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
	"sessionKey": "AQoDYXdzEJr...",
	"consoleUrl": "https://aws.amazon.com/console/",
}

type LeaseResponse

type LeaseResponse struct {
	AccountID                string                 `json:"accountId"`
	PrincipalID              string                 `json:"principalId"`
	ID                       string                 `json:"id"`
	LeaseStatus              db.LeaseStatus         `json:"leaseStatus"`
	LeaseStatusReason        db.LeaseStatusReason   `json:"leaseStatusReason"`
	CreatedOn                int64                  `json:"createdOn"`
	LastModifiedOn           int64                  `json:"lastModifiedOn"`
	BudgetAmount             float64                `json:"budgetAmount"`
	BudgetCurrency           string                 `json:"budgetCurrency"`
	BudgetNotificationEmails []string               `json:"budgetNotificationEmails"`
	LeaseStatusModifiedOn    int64                  `json:"leaseStatusModifiedOn"`
	ExpiresOn                int64                  `json:"expiresOn"`
	Metadata                 map[string]interface{} `json:"metadata"`
}

LeaseResponse is the structured JSON Response for an Lease to be returned for APIs

{
	"accountId": "123",
	"principalId": "user",
	"leaseStatus": "Active",
	"createdOn": 56789,
	"lastModifiedOn": 56789,
	"budgetAmount": 300,
	"BudgetCurrency": "USD",
	"BudgetNotificationEmails": ["usermsid@test.com", "managersmsid@test.com"]
}

func CreateLeaseResponse

func CreateLeaseResponse(lease *db.Lease) *LeaseResponse

CreateLeaseResponse creates an Lease Response based on the provided Lease

type UsageResponse

type UsageResponse struct {
	PrincipalID  string  `json:"principalId"`  // User Principal ID
	AccountID    string  `json:"accountId"`    // AWS Account ID
	StartDate    int64   `json:"startDate"`    // Usage start date Epoch Timestamp
	EndDate      int64   `json:"endDate"`      // Usage ends date Epoch Timestamp
	CostAmount   float64 `json:"costAmount"`   // Cost Amount for given period
	CostCurrency string  `json:"costCurrency"` // Cost currency
	TimeToLive   int64   `json:"timeToLive"`   // ttl attribute
}

UsageResponse is the serialized JSON Response for an account usage to be returned by usage API

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL