utils

package module
v0.0.0-...-ba0deaf Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusBadRequestDefaultMessage          = "The request could not be understood by the server due to malformed syntax."
	StatusUnauthorizedDefaultMessage        = "The request requires user authentication."
	StatusNotFoundDefaultMessage            = "The requested resource could not be found."
	StatusInternalServerErrorDefaultMessage = "The server encountered an unexpected condition which prevented it from fulfilling the request."
)
View Source
const (
	StatusBadRequestDefaultCode          = "BAD_REQUEST"
	StatusUnauthorizedDefaultCode        = "UNAUTHORIZED"
	StatusNotFoundDefaultCode            = "NOT_FOUND"
	StatusInternalServerErrorDefaultCode = "INTERNAL_SERVER_ERROR"
)

Variables

This section is empty.

Functions

func BadRequestResponse

func BadRequestResponse(message ...string) (events.APIGatewayProxyResponse, error)

BadRequestResponse creates a bad request response (status code 400) with an optional message

func BodyToJSON

func BodyToJSON[T any](body T) (string, error)

func InternalServerErrorResponse

func InternalServerErrorResponse(message ...string) (events.APIGatewayProxyResponse, error)

InternalServerErrorResponse creates an internal server error response (status code 500) with an optional message

func JSONtoBody

func JSONtoBody[T any](jsonStr string, body *T) error

func NewRequestBody

func NewRequestBody[T any](proxyRequest events.APIGatewayProxyRequest, additionalData T) (T, error)

func NotFoundResponse

func NotFoundResponse(message ...string) (events.APIGatewayProxyResponse, error)

NotFoundResponse creates a not found response (status code 404) with an optional message

func SuccessResponse

func SuccessResponse(body interface{}) (events.APIGatewayProxyResponse, error)

SuccessResponse creates a successful response (status code 200) with a required body

func UnauthorizedResponse

func UnauthorizedResponse(message ...string) (events.APIGatewayProxyResponse, error)

UnauthorizedResponse creates an unauthorized response (status code 401) with an optional message

Types

type DefaultBody

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

type HTTPRequestsUtils

type HTTPRequestsUtils interface {
	// Get は指定されたURLにGETリクエストを送信し、HTTPResponseを返します
	Get(url string) (*HTTPResponse, error)
	// Post は指定されたURLにPOSTリクエストを送信し、HTTPResponseを返します
	Post(url string, contentType string, body []byte) (*HTTPResponse, error)
}

HTTPRequestsUtils インターフェースはHTTPリクエストのメソッドを定義します

func NewHTTPRequestsUtils

func NewHTTPRequestsUtils() HTTPRequestsUtils

NewHTTPRequestsUtils は新しい HTTPRequestsUtils インスタンスを作成します

type HTTPResponse

type HTTPResponse struct {
	StatusCode int
	Body       []byte
	Header     http.Header
}

HTTPResponse はHTTPリクエストの結果を表す構造体です

Jump to

Keyboard shortcuts

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