http

package
v0.0.0-...-8edc08b Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthRequest

type AuthRequest struct {
	Username string `json:"username" example:"test@example.com"`
	Password string `json:"password" example:"mycoolpassword123"`
}

func (*AuthRequest) IsValid

func (r *AuthRequest) IsValid() error

type AuthResponse

type AuthResponse struct {
	AccessToken string `json:"accessToken"`
}

type ContextKey

type ContextKey string
const ContextUsername ContextKey = "username"

type GenericResponse

type GenericResponse struct {
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
}

func GenericError

func GenericError(message string) GenericResponse

type Handler

type Handler struct {
	Config  config.HTTPConfig
	Usecase IUsecase
}

func New

func New(cfg config.HTTPConfig, uc IUsecase) *Handler

func (*Handler) Auth

func (h *Handler) Auth(w http.ResponseWriter, r *http.Request)

Auth godoc @Summary Request to issue access token @Tags auth @Accept json @Produce json @Param data body AuthRequest true "Input model" @Success 200 {object} AuthResponse @Failure 401 {object} GenericResponse @Failure 400 {object} GenericResponse @Failure 500 {object} GenericResponse @Router /api/auth [Post] @BasePath /

func (*Handler) AuthMdw

func (h *Handler) AuthMdw(next http.Handler) http.Handler
func (h *Handler) GetLink(w http.ResponseWriter, r *http.Request)

GetLink godoc @Summary Go to original url @Tags link @Accept json @Produce json @Param short path string true "short relative url" @Success 302 @Failure 404 @Failure 500 @Router /{short} [Get] @BasePath /

func (h *Handler) PutLink(w http.ResponseWriter, r *http.Request)

PutLink godoc @Summary Create new short link @Tags link @Accept json @Produce json @Param Authorization header string true "Bearer token" @Param data body PutLinkRequest true "Input model" @Success 200 {object} PutLinkResponse @Failure 401 {object} GenericResponse @Failure 400 {object} GenericResponse @Failure 500 {object} GenericResponse @Router /api/link [Put] @BasePath /

func (*Handler) Run

func (h *Handler) Run() error

type IUsecase

type IUsecase interface {
	Auth(ctx context.Context, username, password string) error
	PutLink(ctx context.Context, originalURL, username string) (string, error)
	GetOriginalLink(ctx context.Context, short string) (string, error)
}

type PutLinkRequest

type PutLinkRequest struct {
	OriginalURL string `json:"originalURL" example:"https://example.com/page1?id=3"`
}

func (*PutLinkRequest) IsValid

func (r *PutLinkRequest) IsValid() error

type PutLinkResponse

type PutLinkResponse struct {
	ShortURL string `json:"shortURL" example:"https://caurlshortener.com/128hbcddhs712"`
}

Jump to

Keyboard shortcuts

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