memory

package
v1.9.14 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 13 Imported by: 0

README

Буфер для хранения данных в памяти.

Реализует интерфейс io.ReadWriteCloser и стратегию хранения данных в памяти приложения.

Объект конфигурации.
type Config struct {
    Compressor    string
    NameForMetric string
}

Описание полей:

Поле Описание Значение по умолчанию Доступные значения
Compressor Тип алгоритма сжатия, этот параметр может быть передан одним из 3-х методов:
- флаг командной строки --buffer.memory.compressor
- переменная окружения BUFFER_MEMORY_COMPRESSOR
- значение в конфиг файле buffer.memory.compressor
none - none - не использовать сжатие;
- lz4 - сжимает входящий поток байтов алгоритмом lz4.
NameForMetric Имя буфера в метриках, устанавливает в ручную, должно быть установлено на этапе конфигурирования приложения, до создание объекта буфера
Метрики

Метрики добавляются автоматически и не могут быть отключены.

go_buffer_memory_bytes - счетчик кол. записанных и прочитанных байтов. Доступные лейблы в метрике:

  • app - имя приложения;
  • name - имя буфера из поля конфига NameForMetric;
  • action - тип действия, запись - write, чтение - read;
  • compressor - тип выбранного алгоритма сжатия, если выбран алгоритм сжатия lz4 то метрика будет писаться дважды, на каждое действие записи/чтения, до сжатия и после сжатия.

Documentation

Index

Constants

View Source
const (
	CompressorFieldName = "buffer.memory.compressor"

	CompressorNone = "none"
	CompressorLZ4  = "lz4"

	CompressorDefault = CompressorNone
)

Variables

View Source
var Component = &app.Component{
	Dependencies: app.Components{
		configurator.Component,
		metric.Component,
	},
	Constructor: app.Constructor(func(container container.Container) error {
		return container.Provides(
			NewConfig,
			NewWithConfigurator,
			func(buffer *Memory) Buffer { return buffer },
		)
	}),
	BindFlags: app.BindFlags(BindFlags),
}

Functions

func BindFlags added in v1.9.14

func BindFlags(flagSet *pflag.FlagSet, container container.Container) error

Types

type Buffer added in v1.8.12

type Buffer io.ReadWriteCloser

type BufferReader added in v1.8.12

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

func NewBufferReader added in v1.8.12

func NewBufferReader() *BufferReader

func (*BufferReader) Len added in v1.8.12

func (reader *BufferReader) Len() int

func (*BufferReader) Read added in v1.8.12

func (reader *BufferReader) Read(p []byte) (int, error)

func (*BufferReader) Reset added in v1.8.12

func (reader *BufferReader) Reset()

func (*BufferReader) Write added in v1.8.12

func (reader *BufferReader) Write(p []byte) (int, error)

type BufferWriter added in v1.8.12

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

func NewBufferWriter added in v1.8.12

func NewBufferWriter() *BufferWriter

func (*BufferWriter) Bytes added in v1.8.12

func (writer *BufferWriter) Bytes() []byte

func (*BufferWriter) Len added in v1.8.12

func (writer *BufferWriter) Len() int

func (*BufferWriter) Reset added in v1.8.12

func (writer *BufferWriter) Reset()

func (*BufferWriter) Write added in v1.8.12

func (writer *BufferWriter) Write(p []byte) (int, error)

type Config

type Config struct {
	Compressor    string
	NameForMetric string
}

func Configuration

func Configuration(config *Config, configurator configurator.Configurator) *Config

func NewConfig

func NewConfig() *Config

type LZ4Reader added in v1.8.12

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

func NewLZ4Reader added in v1.8.12

func NewLZ4Reader(reader Reader) *LZ4Reader

func (LZ4Reader) Len added in v1.8.12

func (reader LZ4Reader) Len() int

func (LZ4Reader) Read added in v1.8.12

func (reader LZ4Reader) Read(p []byte) (int, error)

func (LZ4Reader) Reset added in v1.8.12

func (reader LZ4Reader) Reset()

func (LZ4Reader) Write added in v1.8.12

func (reader LZ4Reader) Write(p []byte) (int, error)

type Lz4Writer added in v1.8.12

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

func NewLz4Writer added in v1.8.12

func NewLz4Writer(writer Writer) *Lz4Writer

func (*Lz4Writer) Bytes added in v1.8.12

func (writer *Lz4Writer) Bytes() []byte

func (*Lz4Writer) Len added in v1.8.12

func (writer *Lz4Writer) Len() int

func (*Lz4Writer) Reset added in v1.8.12

func (writer *Lz4Writer) Reset()

func (*Lz4Writer) Write added in v1.8.12

func (writer *Lz4Writer) Write(p []byte) (int, error)

type Memory

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

func New

func New(config *Config, metrics *metric.Metric) (*Memory, error)

func NewMemory

func NewMemory(options ...Option) *Memory

func NewWithConfigurator

func NewWithConfigurator(config *Config, configurator configurator.Configurator, metric *metric.Metric) (*Memory, error)

func (*Memory) Close

func (memory *Memory) Close() error

func (*Memory) Read

func (memory *Memory) Read(p []byte) (int, error)

func (*Memory) Write

func (memory *Memory) Write(p []byte) (int, error)

type MetricReader added in v1.8.12

type MetricReader struct {
	Reader
	// contains filtered or unexported fields
}

func NewMetricReader added in v1.8.12

func NewMetricReader(reader Reader, counter prometheus.Counter) *MetricReader

func (*MetricReader) Read added in v1.8.12

func (metric *MetricReader) Read(buffer []byte) (int, error)

type MetricWrite added in v1.8.12

type MetricWrite struct {
	Writer
	// contains filtered or unexported fields
}

func NewMetricWrite added in v1.8.12

func NewMetricWrite(writer Writer, counter prometheus.Counter) *MetricWrite

func (*MetricWrite) Write added in v1.8.12

func (metric *MetricWrite) Write(buffer []byte) (int, error)

type Option added in v1.8.12

type Option func(memory *Memory)

func WithLZ4Reader added in v1.8.12

func WithLZ4Reader() Option

func WithLz4Writer added in v1.8.12

func WithLz4Writer() Option

func WithReaderMetric added in v1.8.12

func WithReaderMetric(counter prometheus.Counter) Option

func WithWriterMetric added in v1.8.12

func WithWriterMetric(counter prometheus.Counter) Option

type Reader added in v1.8.12

type Reader interface {
	io.Reader
	io.Writer
	Reset()
	Len() int
}

type Writer added in v1.8.12

type Writer interface {
	io.Writer
	Bytes() []byte
	Reset()
	Len() int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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