server

package
v0.0.0-...-ecfe752 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2021 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrBadRequest

func ErrBadRequest(err error) render.Renderer

ErrBadRequest returns bad request error response

func ErrInternalServer

func ErrInternalServer(err error) render.Renderer

ErrInternalServer returns internal server error response

func ErrUnauthorized

func ErrUnauthorized(err error) render.Renderer

ErrUnauthorized to render unathorized error

Types

type AlfamartPaymentCallbackRequest

type AlfamartPaymentCallbackRequest struct {
	PaymentID   string    `json:"payment_id"`
	PaymentCode string    `json:"payment_code"`
	PaidAt      time.Time `json:"paid_at"`
	ExternalID  string    `json:"external_id"`
	CustomerID  uint64    `json:"customer_id"`
}

AlfamartPaymentCallbackRequest is a struct that sent by alfamart service on payment callback

type AuthRequest

type AuthRequest struct {
	Email    string `json:"email"`
	Password string `json:"password"`
}

AuthRequest is a struct for register and login endpoint's request body

type ErrResponse

type ErrResponse struct {
	Err            error `json:"-"`
	HTTPStatusCode int   `json:"-"`

	StatusText string `json:"status"`
	ErrorText  string `json:"error,omitempty"`
}

ErrResponse contains err, http_status_code, status_text, app_code, error_text

func (*ErrResponse) Render

func (e *ErrResponse) Render(w http.ResponseWriter, r *http.Request) error

Render error response

type Notifier

type Notifier interface {
	Notify(ctx context.Context, customer *customer.Customer, body interface{})
}

Notifier is an abstraction of HTTP Client that will notifies callback url by firing POST HTTP request

func GetNotifier

func GetNotifier() Notifier

GetNotifier creates new notifier or returns created notifier

type NotifierImplementation

type NotifierImplementation struct {
	HTTPClient *http.Client
}

NotifierImplementation is the default implementation of Notifier

func (*NotifierImplementation) Notify

func (n *NotifierImplementation) Notify(
	ctx context.Context,
	customer *customer.Customer,
	body interface{},
)

Notify notifies customer's callback url

type Server

type Server struct {
	CustomerRepository datastore.CustomerRepository
	Jeff               *jeff.Jeff
}

Server holds server's required resources

func NewServer

func NewServer(db *gorm.DB) *Server

NewServer returns new server

func (*Server) AlfamartPaymentCallbackHandler

func (s *Server) AlfamartPaymentCallbackHandler() http.HandlerFunc

AlfamartPaymentCallbackHandler handles payment callback from alfamart service

func (*Server) LoginHandler

func (s *Server) LoginHandler() http.HandlerFunc

LoginHandler handles request for login authentication

func (*Server) RegisterHandler

func (s *Server) RegisterHandler() http.HandlerFunc

RegisterHandler handles request for creating a customer

func (*Server) Router

func (s *Server) Router() *chi.Mux

Router returns server routes

func (*Server) SetCallbackURLHandler

func (s *Server) SetCallbackURLHandler() http.HandlerFunc

SetCallbackURLHandler handles request for setting customer's callback url

type SetCallbackURLRequest

type SetCallbackURLRequest struct {
	CallbackURL string `json:"callback_url"`
}

SetCallbackURLRequest is a struct for set callback url endpoint's request body

Jump to

Keyboard shortcuts

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