diff --git a/pkg/cache/main.go b/pkg/cache/main.go new file mode 100644 index 0000000..0204727 --- /dev/null +++ b/pkg/cache/main.go @@ -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)) + } +}