Skip to content

Commit

Permalink
any
Browse files Browse the repository at this point in the history
  • Loading branch information
pieceowater committed Sep 27, 2024
1 parent b6a8639 commit aa7a7ef
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ import (
"log"
)

func HandleMessage(msg gossiper.AMQMessage) interface{} {
func HandleMessage(msg gossiper.AMQMessage) any {
log.Printf("Received message: %s", msg.Pattern)
return "OK"
}
Expand All @@ -77,7 +77,7 @@ func main() {
conf := GetConfig()

// Initialize and start the consumers
gossiper.Setup(conf, func(msg []byte) interface{} {
gossiper.Setup(conf, func(msg []byte) any {
var customMessage gossiper.AMQMessage
err := json.Unmarshal(msg, &customMessage)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
// HandleMessage processes incoming RabbitMQ messages.
// It receives an AMQMessage, logs the pattern, and returns a response.
// This is where you can add custom logic to route or process messages.
func HandleMessage(msg gossiper.AMQMessage) interface{} {
func HandleMessage(msg gossiper.AMQMessage) any {
// Log the received message's pattern
log.Printf("Received message: %s", msg.Pattern)
return "OK" // Return a response; modify this as needed
Expand Down Expand Up @@ -41,7 +41,7 @@ func main() {

// Initialize and start consuming messages
// Pass a handler function to process each message
gossiper.Setup(conf, func(msg []byte) interface{} {
gossiper.Setup(conf, func(msg []byte) any {
var customMessage gossiper.AMQMessage

// Attempt to unmarshal the received message into a custom structure
Expand Down
2 changes: 1 addition & 1 deletion gossiper.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Tools = tools.Tools
// Parameters:
// - cfg: the configuration structure containing environment and AMQP settings.
// - messageHandler: a callback function to handle incoming RabbitMQ messages.
func Setup(cfg config.Config, messageHandler func([]byte) interface{}) {
func Setup(cfg config.Config, messageHandler func([]byte) any) {
// Reference EnvVars to make sure it's initialized.
_ = EnvVars

Expand Down
8 changes: 4 additions & 4 deletions internal/consume/mqp/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ type AMQP struct {
// DefaultMessage defines the default message structure for Gossiper
// Pattern is the type or category of the message, Data is the payload
type DefaultMessage struct {
Pattern string `json:"pattern"`
Data interface{} `json:"data"`
Pattern string `json:"pattern"`
Data any `json:"data"`
}

// DefaultHandleMessage is the default message handler used by Gossiper.
// It unmarshals the message into a DefaultMessage structure and logs the pattern.
func DefaultHandleMessage(msg []byte) interface{} {
func DefaultHandleMessage(msg []byte) any {
var defaultMessage DefaultMessage
err := json.Unmarshal(msg, &defaultMessage)
if err != nil {
Expand All @@ -36,7 +36,7 @@ func DefaultHandleMessage(msg []byte) interface{} {

// SetupAMQPConsumers initializes and starts RabbitMQ consumers based on the configuration in AMQP.
// It processes incoming messages and uses the provided messageHandler to handle them.
func (n *AMQP) SetupAMQPConsumers(messageHandler func([]byte) interface{}) {
func (n *AMQP) SetupAMQPConsumers(messageHandler func([]byte) any) {
// Use the default handler if no custom handler is provided
if messageHandler == nil {
messageHandler = DefaultHandleMessage
Expand Down
6 changes: 3 additions & 3 deletions internal/tools/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (t *Tools) SplitOnce(s string, sep rune) []string {
}

// ToString converts any value to a string
func (t *Tools) ToString(val interface{}) string {
func (t *Tools) ToString(val any) string {
return fmt.Sprintf("%v", val)
}

Expand All @@ -70,7 +70,7 @@ func (t *Tools) Join(arr []string, sep string) string {
}

// StructToJSON converts a struct to JSON format
func (t *Tools) StructToJSON(v interface{}) (string, error) {
func (t *Tools) StructToJSON(v any) (string, error) {
bytes, err := json.Marshal(v)
if err != nil {
return "", err
Expand All @@ -79,6 +79,6 @@ func (t *Tools) StructToJSON(v interface{}) (string, error) {
}

// JSONToStruct converts JSON to a struct
func (t *Tools) JSONToStruct(data string, v interface{}) error {
func (t *Tools) JSONToStruct(data string, v any) error {
return json.Unmarshal([]byte(data), v)
}

0 comments on commit aa7a7ef

Please sign in to comment.