Browse Source

Add few logs and enable profiling

Alexey Edelev 5 years ago
parent
commit
e585ce3a7a
7 changed files with 22 additions and 4 deletions
  1. 1 0
      go.mod
  2. 2 0
      go.sum
  3. 2 0
      main.go
  4. 4 4
      sasl/sasl.go
  5. 4 0
      scanner/mailscanner.go
  6. 5 0
      scanner/parser.go
  7. 4 0
      web/css/styles.css

+ 1 - 0
go.mod

@@ -11,6 +11,7 @@ require (
 	github.com/gorilla/sessions v1.2.0
 	github.com/jhillyerd/enmime v0.8.0
 	github.com/lyft/protoc-gen-star v0.4.14 // indirect
+	github.com/pkg/profile v1.4.0
 	github.com/spf13/afero v1.2.2 // indirect
 	go.mongodb.org/mongo-driver v1.3.0
 	golang.org/x/crypto v0.0.0-20200221231518-2aa609cf4a9d

+ 2 - 0
go.sum

@@ -81,6 +81,8 @@ github.com/pelletier/go-toml v1.4.0/go.mod h1:PN7xzY2wHTK0K9p34ErDQMlFxa51Fk0OUr
 github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
 github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
 github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
+github.com/pkg/profile v1.4.0 h1:uCmaf4vVbWAOZz36k1hrQD7ijGRzLwaME8Am/7a4jZI=
+github.com/pkg/profile v1.4.0/go.mod h1:NWz/XGvpEW1FyYQ7fCx4dqYBLlfTcE+A9FLAkNKqjFE=
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
 github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=

+ 2 - 0
main.go

@@ -29,6 +29,7 @@ import (
 	sasl "git.semlanik.org/semlanik/gostfix/sasl"
 	scanner "git.semlanik.org/semlanik/gostfix/scanner"
 	web "git.semlanik.org/semlanik/gostfix/web"
+	profile "github.com/pkg/profile"
 )
 
 type GofixEngine struct {
@@ -65,6 +66,7 @@ func main() {
 	// storage.AddEmail("semlanik@semlanik.org", "junkmail@semlanik.org")
 	// storage.AddEmail("junkmail@semlanik.org", "qqqqq@semlanik.org")
 	// storage.AddEmail("junkmail@semlanik.org", "main@semlanik.org")
+	defer profile.Start().Stop()
 	engine := NewGofixEngine()
 	engine.Run()
 }

+ 4 - 4
sasl/sasl.go

@@ -102,7 +102,7 @@ func (s *SaslServer) handleRequest(conn net.Conn) {
 		fullbuf, err := connectionReader.ReadString('\n')
 
 		if err == io.EOF {
-			continue
+			break
 		}
 
 		if err != nil {
@@ -162,9 +162,9 @@ func (s *SaslServer) handleRequest(conn net.Conn) {
 					return
 				}
 
-				// identity := credentialList[0]
-				login := credentialList[1]
-				// password := credentialList[2]
+				// identity := string(credentialList[0])
+				login := string(credentialList[1])
+				// password := string(credentialList[2])
 				//TODO: Use auth here
 				// if login != "semlanik@semlanik.org" || password != "test" {
 				if true {

+ 4 - 0
scanner/mailscanner.go

@@ -196,6 +196,8 @@ func (ms *MailScanner) Run() {
 					return
 				}
 				if event.Op&fsnotify.Write == fsnotify.Write {
+					log.Println("iNotify write")
+
 					mailPath := event.Name
 					mailbox := ""
 					for k, v := range ms.emailMaps {
@@ -229,6 +231,8 @@ func (ms *MailScanner) Stop() {
 }
 
 func (ms *MailScanner) readMailFile(mailPath string) (mails []*common.Mail) {
+	log.Println("Read mail file")
+	defer log.Println("Exit read mail file")
 	if !utils.FileExists(mailPath) {
 		return nil
 	}

+ 5 - 0
scanner/parser.go

@@ -79,6 +79,9 @@ func (pd *parseData) reset() {
 }
 
 func parseFile(file *utils.LockedFile) []*common.Mail {
+	log.Println("Parse file")
+	defer log.Println("Exit parse")
+
 	var emails []*common.Mail
 
 	pd := &parseData{}
@@ -86,6 +89,8 @@ func parseFile(file *utils.LockedFile) []*common.Mail {
 
 	scanner := bufio.NewScanner(file)
 	for scanner.Scan() {
+		log.Println("Scan next line")
+
 		currentText := scanner.Text()
 		if utils.RegExpUtilsInstance().MailIndicator.MatchString(currentText) {
 			if pd.mandatoryHeaders == AllHeaderMask {

+ 4 - 0
web/css/styles.css

@@ -100,4 +100,8 @@ body {
     background: -o-linear-gradient(left, rgba(0, 0, 0, 0) 0%, var(--bg-color) 20%, var(--bg-color) 100%); /* Opera 11.10+ */
     background: -ms-linear-gradient(left, rgba(0, 0, 0, 0) 0%, var(--bg-color) 20%, var(--bg-color) 100%); /* IE10+ */
     background: linear-gradient(to right, rgba(0, 0, 0, 0) 0%, var(--bg-color) 20%, var(--bg-color) 100%); /* W3C */
+}
+
+#copyrightBox {
+    color: var(--secondary-dark-color)
 }