infra

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2025 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLogger

func NewLogger(cfg LoggerConfig) *slog.Logger

func NewRedisClient

func NewRedisClient(cfg RedisConfig) *redis.Client

func NewS3Client

func NewS3Client(cfg S3Config) (*s3.S3, error)

NewS3Client creates a new S3 client using the provided configuration.

func NewServer

func NewServer(cfg ServerConfig) (*fiber.App, error)

func RedisHealthCheck

func RedisHealthCheck(ctx context.Context, client *redis.Client) error

func RunWithGracefulShutdown

func RunWithGracefulShutdown(cfg RabbitmqConfig) error

RunWithGracefulShutdown runs the application with RabbitMQ and handles graceful shutdown

func S3HealthCheck

func S3HealthCheck(ctx context.Context, client *s3.S3, bucketName string) error

S3HealthCheck verifies the S3 service availability.

Types

type ChatRoomConfig

type ChatRoomConfig struct {
	MaxChannelMember int
	MaxGroupMember   int
}

type DatabaseConfig

type DatabaseConfig struct {
	PgPoolHost         string
	PgPoolPort         int
	DatabaseName       string
	DatabaseUser       string
	DatabasePassword   string
	DatabaseTimezone   string
	DatabaseSslMode    string
	DatabaseLogEnabled bool
}

type GoogleAppConfig

type GoogleAppConfig struct {
	ProjectID   string
	Credentials string
}

type JwtConfig

type JwtConfig struct {
	SecretKey string
	ExpireMin int
	ApiKey    string
}

type Logger

type Logger interface {
	Debug(msg string, args ...any)
	DebugContext(ctx context.Context, msg string, args ...any)
	Error(msg string, args ...any)
	ErrorContext(ctx context.Context, msg string, args ...any)
	Info(msg string, args ...any)
	InfoContext(ctx context.Context, msg string, args ...any)
	Warn(msg string, args ...any)
	WarnContext(ctx context.Context, msg string, args ...any)
}

type LoggerConfig

type LoggerConfig struct {
	Env   string
	Level slog.Level
}

type Rabbitmq

type Rabbitmq struct {
	Conn    *amqp.Connection
	Channel *amqp.Channel
}

func NewRabbitmqClient

func NewRabbitmqClient(cfg RabbitmqConfig) (*Rabbitmq, error)

NewRabbitmqClient initializes a RabbitMQ client with proper error handling

func (*Rabbitmq) Close

func (r *Rabbitmq) Close()

Close gracefully shuts down the RabbitMQ connection and channel

type RabbitmqConfig

type RabbitmqConfig struct {
	Host          string
	Vhost         string
	Port          int
	User          string
	Password      string
	TotalQueue    int
	ContainerName string
}

type RedisConfig

type RedisConfig struct {
	Host              string
	Port              int32
	Password          string
	UserChannelPrefix string
	ContainerName     string
}

type S3Config

type S3Config struct {
	AccessKey              string
	SecretKey              string
	Region                 string
	BucketName             string
	Endpoint               string
	RoomsImageFolder       string
	RoomImageMaxUploadSize int64
	MaxUploadSize          int64
	PreSignedExpireMin     int
}

S3Config holds the configuration for the S3 client.

type ServerConfig

type ServerConfig struct {
	Host             string
	Port             int
	ApiPrefix        string
	WebsocketPrefix  string
	ApiVersion       string
	WebsocketVersion string
	LogEnable        bool
	JwtSecretKey     string
}

type TxDB

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

func NewDBWithTX

func NewDBWithTX(cfg DatabaseConfig) (*TxDB, func(), error)

func (*TxDB) Drop

func (t *TxDB) Drop(ctx context.Context) error

func (*TxDB) GetDB

func (t *TxDB) GetDB(ctx context.Context) bun.IDB

func (*TxDB) Migrate

func (t *TxDB) Migrate(ctx context.Context) error

func (*TxDB) RegisterModel

func (t *TxDB) RegisterModel(models ...interface{})

func (*TxDB) RunInTransaction

func (t *TxDB) RunInTransaction(ctx context.Context, fn func(ctx context.Context) error) error

func (*TxDB) Seed

func (tx *TxDB) Seed()

Seed function to populate the database

Jump to

Keyboard shortcuts

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