paste

package
v0.0.0-...-cd7fc74 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContentLimitMaxDatabase  = 4  //100 << 10 // 100 KiB
	ContentLimitMaxAnonimous = 10 //1 << 19   // 0.5 MiB
	ContentLimitMaxTotal     = 20 //10 << 20  // 10 MiB
)

Variables

View Source
var (
	ErrContentOfZeroSize                  = reqerrors.New(http.StatusBadRequest, "unable to store the content of zero size")
	ErrContentLargerThanMaxAnonimousLimit = reqerrors.New(http.StatusBadRequest, "unable anonimously to store the content larger than "+strconv.Itoa(ContentLimitMaxAnonimous)+" bytes")
	ErrContentLargerThanTotalMaxLimit     = reqerrors.New(http.StatusBadRequest, "unable to store the content larger than "+strconv.Itoa(ContentLimitMaxTotal)+" bytes")
	ErrHeaderExpiresAtIsEmpty             = reqerrors.New(http.StatusBadRequest, "header 'Expires-At' is empty")

	ErrPasteNotFound = reqerrors.New(http.StatusNotFound, "paste not found")
)

Functions

This section is empty.

Types

type DatabaseAdapterer

type DatabaseAdapterer interface {
	CreatePaste(ctx context.Context, paste Paste) error
	GetAllPastes(ctx context.Context) ([]Paste, error)
	GetPasteById(ctx context.Context, id int64) (Paste, error)
	UpdatePasteById(ctx context.Context, id int64, paste Paste) error
	DeletePasteById(ctx context.Context, id int64) error
}

type DummyHttpAdapter

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

func NewDummyHttpAdapter

func NewDummyHttpAdapter(db *database.PostgresDatabase) *DummyHttpAdapter

func (*DummyHttpAdapter) GetGeneratedPasteId

func (a *DummyHttpAdapter) GetGeneratedPasteId(ctx context.Context) (string, error)

type HttpAdapterer

type HttpAdapterer interface {
	GetGeneratedPasteId(ctx context.Context) (string, error)
}

type HttpHandler

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

func NewHttpHandler

func NewHttpHandler(service Servicer) *HttpHandler

func (*HttpHandler) CreatePaste

func (h *HttpHandler) CreatePaste(c *gin.Context)

func (*HttpHandler) DeletePasteById

func (h *HttpHandler) DeletePasteById(c *gin.Context)

func (*HttpHandler) GetAllPastes

func (h *HttpHandler) GetAllPastes(c *gin.Context)

func (*HttpHandler) GetPasteById

func (h *HttpHandler) GetPasteById(c *gin.Context)

func (*HttpHandler) IsPasteContentExistsById

func (h *HttpHandler) IsPasteContentExistsById(c *gin.Context)

func (*HttpHandler) UpdatePasteById

func (h *HttpHandler) UpdatePasteById(c *gin.Context)

type MongoStorageAdapter

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

func NewMongoStorageAdapter

func NewMongoStorageAdapter(db *database.MongoDatabase) *MongoStorageAdapter

func (*MongoStorageAdapter) CreateOrUpdatePasteContentById

func (a *MongoStorageAdapter) CreateOrUpdatePasteContentById(ctx context.Context, id int64, content []byte) error

func (*MongoStorageAdapter) CreatePasteContentById

func (a *MongoStorageAdapter) CreatePasteContentById(ctx context.Context, id int64, content []byte) error

func (*MongoStorageAdapter) DeletePasteContentById

func (a *MongoStorageAdapter) DeletePasteContentById(ctx context.Context, id int64) error

func (*MongoStorageAdapter) GetPasteContentById

func (a *MongoStorageAdapter) GetPasteContentById(ctx context.Context, id int64) ([]byte, error)

func (*MongoStorageAdapter) IsPasteContentExistsById

func (a *MongoStorageAdapter) IsPasteContentExistsById(ctx context.Context, id int64) (bool, error)

type OuterPaste

type OuterPaste struct {
	Base64Id  string `json:"base64Id"`
	UserId    int64  `json:"userId"`
	Content   []byte `json:"content"`
	CreatedAt string `json:"createdAt"`
	ExpiresAt string `json:"expiresAt"`
}

func NewOuterPaste

func NewOuterPaste(c *gin.Context) (OuterPaste, error)

func (OuterPaste) ToPaste

func (p OuterPaste) ToPaste() (Paste, error)

type Paste

type Paste struct {
	Id        int64
	UserId    *int64
	Content   []byte
	CreatedAt time.Time
	ExpiresAt time.Time
}

func (Paste) ToOuterPaste

func (p Paste) ToOuterPaste() (OuterPaste, error)

type PostgresDatabaseAdapter

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

func (*PostgresDatabaseAdapter) CreatePaste

func (a *PostgresDatabaseAdapter) CreatePaste(ctx context.Context, paste Paste) error

func (*PostgresDatabaseAdapter) DeletePasteById

func (a *PostgresDatabaseAdapter) DeletePasteById(ctx context.Context, id int64) error

func (*PostgresDatabaseAdapter) GetAllPastes

func (a *PostgresDatabaseAdapter) GetAllPastes(ctx context.Context) ([]Paste, error)

func (*PostgresDatabaseAdapter) GetPasteById

func (a *PostgresDatabaseAdapter) GetPasteById(ctx context.Context, id int64) (Paste, error)

func (*PostgresDatabaseAdapter) UpdatePasteById

func (a *PostgresDatabaseAdapter) UpdatePasteById(ctx context.Context, id int64, paste Paste) error

type Service

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

func NewService

func NewService(
	databaseAdapterer DatabaseAdapterer,
	storageAdapterer StorageAdapterer,
	httpAdapterer HttpAdapterer,
) *Service

func (*Service) CreatePaste

func (s *Service) CreatePaste(ctx context.Context, outerPaste OuterPaste) (string, error)

func (*Service) DeletePasteById

func (s *Service) DeletePasteById(ctx context.Context, base64Id string) error

func (*Service) GetAllPastes

func (s *Service) GetAllPastes(ctx context.Context) ([]OuterPaste, error)

func (*Service) GetPasteById

func (s *Service) GetPasteById(ctx context.Context, base64Id string) (OuterPaste, error)

func (*Service) IsPasteContentExistsById

func (s *Service) IsPasteContentExistsById(ctx context.Context, base64Id string) (bool, error)

func (*Service) UpdatePasteById

func (s *Service) UpdatePasteById(ctx context.Context, base64Id string, outerPaste OuterPaste) error

type Servicer

type Servicer interface {
	CreatePaste(ctx context.Context, outerPaste OuterPaste) (string, error)
	GetAllPastes(ctx context.Context) ([]OuterPaste, error)
	GetPasteById(ctx context.Context, base64Id string) (OuterPaste, error)
	UpdatePasteById(ctx context.Context, base64Id string, outerPaste OuterPaste) error
	DeletePasteById(ctx context.Context, base64Id string) error
	IsPasteContentExistsById(ctx context.Context, base64Id string) (bool, error)
}

type StorageAdapterer

type StorageAdapterer interface {
	CreatePasteContentById(ctx context.Context, id int64, content []byte) error
	CreateOrUpdatePasteContentById(ctx context.Context, id int64, content []byte) error
	GetPasteContentById(ctx context.Context, id int64) ([]byte, error)
	DeletePasteContentById(ctx context.Context, id int64) error
	IsPasteContentExistsById(ctx context.Context, id int64) (bool, error)
}

Jump to

Keyboard shortcuts

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