httpadapters

package
v0.0.0-...-2f108ac Latest Latest
Warning

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

Go to latest
Published: May 28, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildBadRequestResponse

func BuildBadRequestResponse(err error, w http.ResponseWriter)

func BuildBadRequestResponseWithErrorArray

func BuildBadRequestResponseWithErrorArray(apierrs []*apierror.ApiError, code, message string, w http.ResponseWriter)

func BuildCreatedResponse

func BuildCreatedResponse(result interface{}, apierr error, w http.ResponseWriter)

func BuildOkResponse

func BuildOkResponse(result interface{}, apierr error, w http.ResponseWriter)

func BuildResponse

func BuildResponse(result interface{}, apierr error, status int, w http.ResponseWriter)

func BuildUnauthorizedResponse

func BuildUnauthorizedResponse(w http.ResponseWriter)

func GetClientIP

func GetClientIP(r *http.Request) string

Types

type AccountBody

type AccountBody struct {
	ID             int `json:"id"`
	DocumentNumber int `json:"document_number"`
}

func NewAccount

func NewAccount(id, documentNumber int) *AccountBody

func (*AccountBody) GetDocumentNumber

func (a *AccountBody) GetDocumentNumber() int

func (*AccountBody) GetID

func (a *AccountBody) GetID() int

func (*AccountBody) SetDocumentNumber

func (a *AccountBody) SetDocumentNumber(documentNumber int)

func (*AccountBody) SetID

func (a *AccountBody) SetID(id int)

type AccountsHttpAdapter

type AccountsHttpAdapter struct {
	// contains filtered or unexported fields
}

func NewAccountsHttpAdapter

func NewAccountsHttpAdapter(service *accounts.Service) *AccountsHttpAdapter

func (*AccountsHttpAdapter) CreateAccount

func (u *AccountsHttpAdapter) CreateAccount(w http.ResponseWriter, r *http.Request)

func (*AccountsHttpAdapter) GetAccount

func (u *AccountsHttpAdapter) GetAccount(w http.ResponseWriter, r *http.Request)

type Endpoint

type Endpoint struct {
	Method      string
	Pattern     string
	Function    http.HandlerFunc
	Middlewares []func(http.Handler) http.Handler
}

type Error

type Error struct {
	Code    string           `json:"code"`
	Message string           `json:"message"`
	Error   string           `json:"error,omitempty"`
	Errors  []string         `json:"errors,omitempty"`
	Stack   []apierror.Stack `json:"stack"`
}

type HTTPAdapter

type HTTPAdapter struct {
	Middlewares []func(http.Handler) http.Handler
	// contains filtered or unexported fields
}

func NewHTTPAdapter

func NewHTTPAdapter(routes []Route, timeout int) *HTTPAdapter

Returns an adapter for run http server routes []Route routes from application timeout int duration in seconds

func (*HTTPAdapter) Serve

func (h *HTTPAdapter) Serve(port string)

Serves http application

type Payload

type Payload struct {
	*Error `json:"error,omitempty"`
	Data   interface{} `json:"data,omitempty"`
}

type Response

type Response struct {
	StatusCode int         `json:"status_code"`
	Data       interface{} `json:"data"`
}

type Route

type Route struct {
	Pattern     string
	Endpoints   []Endpoint
	SubRoutes   []Route
	Middlewares []func(http.Handler) http.Handler
}

type TransactionBody

type TransactionBody struct {
	ID            int       `json:"id"`
	AccountID     int       `json:"account_id"`
	OperationType int       `json:"operation_type_id"`
	Amount        float64   `json:"amount"`
	EventDate     time.Time `json:"event_date"`
}

func (*TransactionBody) GetAccountID

func (tb *TransactionBody) GetAccountID() int

func (*TransactionBody) GetAmount

func (tb *TransactionBody) GetAmount() float64

func (*TransactionBody) GetEventDate

func (tb *TransactionBody) GetEventDate() time.Time

func (*TransactionBody) GetID

func (tb *TransactionBody) GetID() int

func (*TransactionBody) GetOperationType

func (tb *TransactionBody) GetOperationType() int

func (*TransactionBody) SetAccountID

func (tb *TransactionBody) SetAccountID(accountId int)

func (*TransactionBody) SetAmount

func (tb *TransactionBody) SetAmount(amount float64)

func (*TransactionBody) SetEventDate

func (tb *TransactionBody) SetEventDate(date time.Time)

func (*TransactionBody) SetID

func (tb *TransactionBody) SetID(id int)

func (*TransactionBody) SetOperationType

func (tb *TransactionBody) SetOperationType(operationType int)

type TransactionsHttpAdapter

type TransactionsHttpAdapter struct {
	// contains filtered or unexported fields
}

func NewTransactionsHttpAdapter

func NewTransactionsHttpAdapter(service *transactions.Service) *TransactionsHttpAdapter

func (*TransactionsHttpAdapter) CreateTransactions

func (t *TransactionsHttpAdapter) CreateTransactions(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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