Skip to content

Commit

Permalink
chore: cache impl
Browse files Browse the repository at this point in the history
  • Loading branch information
puni9869 committed Oct 20, 2024
1 parent f749ae6 commit e2eeac5
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions pkg/cache/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package cache

import (
"bufio"
"github.com/puni9869/pinmyblogs/pkg/logger"
"net"
"strings"
"time"
)

const PORT = "8080"

func main() {
log := logger.NewLogger()
var err error
l, err := net.Listen("tcp", "127.0.0.1:"+PORT)
if err != nil {
log.WithError(err).Error("failed to listen.")
return
}
defer l.Close()

c, err := l.Accept()
if err != nil {
log.WithError(err).Error("failed to accept the connection request.")
return
}
for {
netData, err := bufio.NewReader(c).ReadString(byte('\n'))
if err != nil {
log.WithError(err).Error("failed to get data from stream.")
return
}
if strings.TrimSpace(string(netData)) == "STOP" {
c.Write([]byte("BYE..."))
return
}

log.Infof("-> %s", string(netData))
t := time.Now()
myTime := t.Format(time.RFC1123Z) + "\n"

c.Write([]byte(myTime))
}
}

0 comments on commit e2eeac5

Please sign in to comment.