srvenv

package
v0.1.17 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StorageTypeFS = "fs"
	StorageTypeS3 = "s3"
)

Variables

This section is empty.

Functions

func ProvideStorageFor

func ProvideStorageFor(ctx context.Context, cfg Config) (storage.Blob, error)

func SetupAMQP

func SetupAMQP(cfg AMQPConfig) (*amqp.Connection, error)

func SetupTelegram

func SetupTelegram(cfg TelegramConfig) (*tgbotapi.BotAPI, error)

Types

type AMQPConfig

type AMQPConfig struct {
	ConnectionURL     string        `env:"AMQP_SERVER_URL,default=amqp://guest:guest@localhost:5672/"`
	HeartBeatDuration time.Duration `env:"AMQP_HEARTBEAT_DURATION,default=12h"`
}

type BackendType

type BackendType string
const (
	BackendTypeRedis    BackendType = "redis"
	BackendTypeInMemory BackendType = "in_memory"
)

type Config

type Config struct {
	Addr                      string      `env:"ADDR,default=localhost:8080"`
	LogLevel                  string      `env:"LOG_LEVEL,default=error"`
	TelegramUpdatesMaxWorkers int         `env:"TELEGRAM_UPDATES_MAX_WORKERS,default=10"`
	FetchingMaxWorkers        int         `env:"FETCHING_MAX_WORKERS,default=10"`
	UploadingMaxWorkers       int         `env:"UPLOADING_MAX_WORKERS,default=5"`
	HashingFunc               string      `env:"FILE_HASHING_FUNC,default=md5"`
	SessionBackend            BackendType `env:"SESSION_BACKEND_TYPE,default=redis"`
	DB                        db.Config
	Redis                     RedisConfig
	Telegram                  TelegramConfig
	RabbitMQ                  AMQPConfig
	Storage                   StorageConfig
}

type Env

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

func Setup

func Setup(ctx context.Context) (*Env, error)

func (Env) AMQP

func (e Env) AMQP() *amqp.Connection

func (Env) Blob

func (e Env) Blob() storage.Blob

func (Env) Config

func (e Env) Config() Config

func (Env) DB

func (e Env) DB() *db.DB

func (Env) SessionBackend

func (e Env) SessionBackend() SessionBackend

func (Env) Telegram

func (e Env) Telegram() *tgbotapi.BotAPI

type RedisConfig

type RedisConfig struct {
	Expiration time.Duration `env:"REDIS_EXPIRATION,default=86400s"`
	Addr       string        `env:"REDIS_ADDR,default=localhost:6380"`
}

type SessionBackend

type SessionBackend interface {
	Get(ctx context.Context, k string) ([]byte, error)
	Set(ctx context.Context, k string, v []byte) error
	Delete(ctx context.Context, k string) error
}

func ProvideSessionBackendFor

func ProvideSessionBackendFor(cfg Config) (SessionBackend, error)

type StorageConfig

type StorageConfig struct {
	Type   string `env:"STORAGE_TYPE,default=fs"`
	Bucket string `env:"UPLOAD_BUCKET_NAME,default=/tmp"`
	S3     storage.S3Config
}

type TelegramConfig

type TelegramConfig struct {
	ProxySchema    string `env:"TELEGRAM_PROXY_SCHEMA,default=http"`
	ProxyAddr      string `env:"TELEGRAM_PROXY_ADDR,default=127.0.0.1:8081"`
	WebHookURL     string `env:"TELEGRAM_WEBHOOK_URL"`
	WebHookAddr    string `env:"TELEGRAM_WEBHOOK_ADDR"`
	Token          string `env:"TELEGRAM_TOKEN"`
	PollingTimeout int    `env:"TELEGRAM_POLLING_TIMEOUT,default=10"`
}

Jump to

Keyboard shortcuts

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