Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
pieceowater committed Oct 1, 2024
1 parent 2a6daca commit 68cf914
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 63 deletions.
118 changes: 56 additions & 62 deletions gossiper.go
Original file line number Diff line number Diff line change
@@ -1,116 +1,110 @@
package gossiper

import (
"github.com/pieceowater-dev/lotof.lib.gossiper/internal/boot"
"github.com/pieceowater-dev/lotof.lib.gossiper/internal/conf"
"github.com/pieceowater-dev/lotof.lib.gossiper/internal/env"
"github.com/pieceowater-dev/lotof.lib.gossiper/internal/infra"
"github.com/pieceowater-dev/lotof.lib.gossiper/internal/tools"
"github.com/pieceowater-dev/lotof.lib.gossiper/internal/tools/formats/errors"
"github.com/pieceowater-dev/lotof.lib.gossiper/internal/tools/formats/filter"
"github.com/pieceowater-dev/lotof.lib.gossiper/internal/tools/formats/pagination"
"github.com/pieceowater-dev/lotof.lib.gossiper/internal"
t "github.com/pieceowater-dev/lotof.lib.gossiper/types"
)

/* ENVIRONMENT */

// Env is an alias for the environment.Env
type Env = env.Env
// Env is an alias for the internal.Env.
type Env = internal.Env

// EnvVars is a pointer alias for the &environment.EnvVars
var EnvVars = &env.EnvVars
// EnvVars is a pointer alias for the internal.EnvVars.
var EnvVars = &internal.EnvVars

/* NETWORK */

// AMQP is an alias for the network.AMQP
type AMQP = infra.AMQP
// AMQP is an alias for the internal.AMQP.
type AMQP = internal.AMQP

// AMQMessage is an alias for the infra.DefaultMessage
type AMQMessage = infra.DefaultMessage
// AMQMessage is an alias for the internal.DefaultMessage.
type AMQMessage = internal.DefaultMessage

/* CONFIG */

// Config is an alias for the config.Config
type Config = conf.Config
// Config is an alias for the internal.Config.
type Config = internal.Config

// EnvConfig is an alias for the config.EnvConfig
type EnvConfig = conf.EnvConfig
// EnvConfig is an alias for the internal.EnvConfig.
type EnvConfig = internal.EnvConfig

// QueueConfig is an alias for the config.QueueConfig
type QueueConfig = conf.QueueConfig
// QueueConfig is an alias for the internal.QueueConfig.
type QueueConfig = internal.QueueConfig

// AMQPConsumerConfig is an alias for the config.AMQPConsumerConfig
type AMQPConsumerConfig = conf.AMQPConsumerConfig
// AMQPConsumerConfig is an alias for the internal.AMQPConsumerConfig.
type AMQPConsumerConfig = internal.AMQPConsumerConfig

// AMQPConsumeConfig is an alias for the config.AMQPConsumeConfig
type AMQPConsumeConfig = conf.AMQPConsumeConfig
// AMQPConsumeConfig is an alias for the internal.AMQPConsumeConfig.
type AMQPConsumeConfig = internal.AMQPConsumeConfig

/* TOOLS */

// Tools is an alias for the tools.Tools
type Tools = tools.Tools
// Tools is an alias for the tools.Tools.
type Tools = internal.Tools

// Satisfies is an alias for the Tools.Satisfies method.
// Satisfies checks if the data satisfies the destination structure.
func Satisfies(data any, dest any) error {
inst := Tools{}
return inst.Satisfies(data, dest)
}

// LogAction is an alias for the Tools.LogAction method.
// LogAction logs an action with the provided data.
func LogAction(action string, data any) {
inst := Tools{}
inst.LogAction(action, data)
}

// NewServiceError is an alias for the Tools.NewServiceError method.
func NewServiceError(message string) *errors.ServiceError {
return errors.NewServiceError(message)
// NewServiceError creates a new internal.ServiceError instance.
func NewServiceError(message string) *internal.ServiceError {
return internal.NewServiceError(message)
}

// Enum with aliases for predefined pagination page length
// Enum with aliases for predefined pagination page length.
const (
TEN = filter.TEN
FIFTEEN = filter.FIFTEEN
TWENTY = filter.TWENTY
TWENTY_FIVE = filter.TWENTY_FIVE
THIRTY = filter.THIRTY
THIRTY_FIVE = filter.THIRTY_FIVE
FORTY = filter.FORTY
FORTY_FIVE = filter.FORTY_FIVE
FIFTY = filter.FIFTY
FIFTY_FIVE = filter.FIFTY_FIVE
SIXTY = filter.SIXTY
SIXTY_FIVE = filter.SIXTY_FIVE
SEVENTY = filter.SEVENTY
SEVENTY_FIVE = filter.SEVENTY_FIVE
EIGHTY = filter.EIGHTY
EIGHTY_FIVE = filter.EIGHTY_FIVE
NINETY = filter.NINETY
NINETY_FIVE = filter.NINETY_FIVE
ONE_HUNDRED = filter.ONE_HUNDRED
TEN = internal.TEN
FIFTEEN = internal.FIFTEEN
TWENTY = internal.TWENTY
TWENTY_FIVE = internal.TWENTY_FIVE
THIRTY = internal.THIRTY
THIRTY_FIVE = internal.THIRTY_FIVE
FORTY = internal.FORTY
FORTY_FIVE = internal.FORTY_FIVE
FIFTY = internal.FIFTY
FIFTY_FIVE = internal.FIFTY_FIVE
SIXTY = internal.SIXTY
SIXTY_FIVE = internal.SIXTY_FIVE
SEVENTY = internal.SEVENTY
SEVENTY_FIVE = internal.SEVENTY_FIVE
EIGHTY = internal.EIGHTY
EIGHTY_FIVE = internal.EIGHTY_FIVE
NINETY = internal.NINETY
NINETY_FIVE = internal.NINETY_FIVE
ONE_HUNDRED = internal.ONE_HUNDRED
)

// PaginatedEntity is a wrapper for tools.PaginatedEntity
// PaginatedEntity wraps internal.PaginatedEntity for convenience.
type PaginatedEntity[T any] struct {
pagination.PaginatedEntity[T]
internal.PaginatedEntity[T]
}

// NewFilter creates a new DefaultFilter instance.
// NewFilter creates a new types.DefaultFilter instance.
func NewFilter[T any]() t.DefaultFilter[T] {
return filter.NewDefaultFilter[T]()
return internal.NewDefaultFilter[T]()
}

// ToPaginated PaginatedEntity directly uses tools.PaginatedEntity
// ToPaginated converts items and count to a PaginatedEntity.
func ToPaginated[T any](items []T, count int) PaginatedEntity[T] {
return PaginatedEntity[T]{pagination.ToPaginated[T](items, count)}
return PaginatedEntity[T]{internal.ToPaginated[T](items, count)}
}

/* BOOTSTRAP */

type Bootstrap = boot.Bootstrap
// Bootstrap is an alias for the internal.Bootstrap.
type Bootstrap = internal.Bootstrap

// Setup is an alias for the Bootstrap.Setup method.
func Setup(cfg conf.Config, startupFunc func() any, messageHandler func([]byte) any) {
// Setup initializes the bootstrap with the given configuration and handlers.
func Setup(cfg internal.Config, startupFunc func() any, messageHandler func([]byte) any) {
b := Bootstrap{}
b.Setup(cfg, startupFunc, messageHandler)
}
93 changes: 93 additions & 0 deletions internal/index.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Package internal provides core functionality and utilities for the Gossiper system.
package internal

import (
"github.com/pieceowater-dev/lotof.lib.gossiper/internal/boot"
"github.com/pieceowater-dev/lotof.lib.gossiper/internal/conf"
"github.com/pieceowater-dev/lotof.lib.gossiper/internal/env"
"github.com/pieceowater-dev/lotof.lib.gossiper/internal/infra"
"github.com/pieceowater-dev/lotof.lib.gossiper/internal/tools"
"github.com/pieceowater-dev/lotof.lib.gossiper/internal/tools/formats/errors"
"github.com/pieceowater-dev/lotof.lib.gossiper/internal/tools/formats/filter"
"github.com/pieceowater-dev/lotof.lib.gossiper/internal/tools/formats/pagination"
t "github.com/pieceowater-dev/lotof.lib.gossiper/types"
)

// Env is an alias for the env.Env type, which manages environment configurations.
type Env = env.Env

// EnvVars is a pointer to the env.EnvVars structure that holds environment variables.
var EnvVars = &env.EnvVars

// AMQP is an alias for the infra.AMQP type, providing methods for AMQP messaging.
type AMQP = infra.AMQP

// DefaultMessage is an alias for the infra.DefaultMessage type, representing default message structure.
type DefaultMessage = infra.DefaultMessage

// Config is an alias for the conf.Config type, which holds application configuration settings.
type Config = conf.Config

// EnvConfig is an alias for the conf.EnvConfig type, containing environment-specific configurations.
type EnvConfig = conf.EnvConfig

// QueueConfig is an alias for the conf.QueueConfig type, representing queue-related configurations.
type QueueConfig = conf.QueueConfig

// AMQPConsumerConfig is an alias for the conf.AMQPConsumerConfig type, holding configurations for AMQP consumers.
type AMQPConsumerConfig = conf.AMQPConsumerConfig

// AMQPConsumeConfig is an alias for the conf.AMQPConsumeConfig type, providing configurations for AMQP consumption.
type AMQPConsumeConfig = conf.AMQPConsumeConfig

// Tools is an alias for the tools.Tools type, providing utility functions for various operations.
type Tools = tools.Tools

// Bootstrap is an alias for the boot.Bootstrap type, which handles application initialization processes.
type Bootstrap = boot.Bootstrap

// ToPaginated converts a slice of items and their count into a PaginatedEntity.
func ToPaginated[T any](items []T, count int) PaginatedEntity[T] {
return PaginatedEntity[T]{pagination.ToPaginated(items, count)}
}

// PaginatedEntity is a wrapper around pagination.PaginatedEntity for easier usage in Gossiper.
type PaginatedEntity[T any] struct {
pagination.PaginatedEntity[T]
}

// NewDefaultFilter creates a new types.DefaultFilter instance using the filter package.
func NewDefaultFilter[T any]() t.DefaultFilter[T] {
return filter.NewDefaultFilter[T]()
}

// Predefined constants for pagination page lengths, allowing for easy configuration.
const (
TEN = filter.TEN
FIFTEEN = filter.FIFTEEN
TWENTY = filter.TWENTY
TWENTY_FIVE = filter.TWENTY_FIVE
THIRTY = filter.THIRTY
THIRTY_FIVE = filter.THIRTY_FIVE
FORTY = filter.FORTY
FORTY_FIVE = filter.FORTY_FIVE
FIFTY = filter.FIFTY
FIFTY_FIVE = filter.FIFTY_FIVE
SIXTY = filter.SIXTY
SIXTY_FIVE = filter.SIXTY_FIVE
SEVENTY = filter.SEVENTY
SEVENTY_FIVE = filter.SEVENTY_FIVE
EIGHTY = filter.EIGHTY
EIGHTY_FIVE = filter.EIGHTY_FIVE
NINETY = filter.NINETY
NINETY_FIVE = filter.NINETY_FIVE
ONE_HUNDRED = filter.ONE_HUNDRED
)

// ServiceError is an alias for the errors.ServiceError type, representing application-specific errors.
type ServiceError = errors.ServiceError

// NewServiceError creates a new instance of errors.ServiceError with the provided message.
func NewServiceError(message string) *errors.ServiceError {
return errors.NewServiceError(message)
}
2 changes: 1 addition & 1 deletion types/filter.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gossiper
package types

// FilterPaginationLengthEnum defines pagination length options.
type FilterPaginationLengthEnum int
Expand Down

0 comments on commit 68cf914

Please sign in to comment.