server

package
v0.0.0-...-7b2cd09 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RatePath      = "/rate"
	SubscribePath = "/subscribe"
)
View Source
const RateTimeout = 3 * time.Second

Variables

This section is empty.

Functions

func NewEngine

func NewEngine(client Client) *gin.Engine

func NewGetRateHandler

func NewGetRateHandler(rateService RateService, timeout time.Duration) func(*gin.Context)

NewGetRateHandler is a handler that fetches the exchange rate between USD and UAH from a RateFetcher interface and returns it as a JSON response.

func NewServer

func NewServer(config config.Config, handler http.Handler) *http.Server

func NewSubscribeUserHandler

func NewSubscribeUserHandler(repo UserRepository) func(*gin.Context)

NewSubscribeUserHandler is a handler that subscribes a user by email. The email is passed as a POST parameter and is required. If the user is already subscribed, returns a 409 Conflict status code. If the subscription is successful, returns a 200 OK status code.

Types

type Client

type Client struct {
	Config      config.Config
	RateService RateService
	UserRepo    UserRepository
}

type RateService

type RateService interface {
	FetchRate(ctx context.Context, from, to string) (*models.Rate, error)
}

type UserRepository

type UserRepository interface {
	Exists(user *models.User) (bool, error)
	Create(user *models.User) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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