Terminal chat application

dunkbing - Aug 28 '22 - - Dev Community

Overview of My Submission

A very simple chat application inside the terminal. The app uses the pubsub to publish the messages to other channel, implemented using Golang which is the programing language that I recently learn.

Submission Category:

  • Wacky Wildcards

Language Used

  • Go 1.18 for developing the app.
  • Use the bubbletea framework for making the terminal ui.

Link to Code

GitHub logo dunkbing / tchat

A simple chatapp with Golang and Redis Pub/Sub

Terminal chat application

A simple chat application inside the terminal with Golang and Redis Pub/Sub.

How it works

How the data is stored:

  • The chat data is stored as keys
    • For each channel contents, the channel: is the prefix key, followed by the channel name.
    • For each message contents, the message: is the prefix key, followed by the channel-name and the message-data in json format.

How the data is accessed:

  • Here is the sample code to access the channel's messages with Go Redis:
# Get the channel's messages
ctx := context.Background()
iter := redis.Client.Scan(ctx, 0, fmt.Sprintf("%s%s*", messagePrefix, m.channel), 0).Iterator()  
var messages []string  
for iter.Next(ctx) {  
   rawMsg := iter.Val()  
   rawMsg = strings.Replace(rawMsg, fmt
Enter fullscreen mode Exit fullscreen mode

Additional Resources / Info

None

Collaborators

@dunkbing


. . . . . .
Terabox Video Player