commit 6347e2f1fe87d70ff8cd2df99103eb6eb70f81ef Author: pro100ton Date: Sat Nov 2 14:07:18 2024 +0300 Initial migration diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f3ebe5b --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.null-ls* +chrono.txt +.DS_Store diff --git a/cmd/main.go b/cmd/main.go new file mode 100644 index 0000000..6479421 --- /dev/null +++ b/cmd/main.go @@ -0,0 +1,39 @@ +package main + +import "fmt" + +func read_from_c(c chan int, b chan int) { + for item := range c { + fmt.Printf("%d", item) + number_multiplied := item * item + b <- number_multiplied + } + close(b) +} + +func read_from_b(b chan int) { + for item := range b { + fmt.Printf("%d", item) + } +} + +func main() { + fmt.Println("main() started") + c := make(chan int) + b := make(chan int) + + fmt.Println("Operation started") + go func() { + fmt.Println("Running writer") + for i := 1; i < 10; i++ { + fmt.Printf("Adding %v to channel c", i) + c <- i + } + close(c) + }() + + go read_from_c(c, b) + for item := range b { + fmt.Printf("%d", item) + } +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..6d1d12e --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module go_sandbox + +go 1.21.3 diff --git a/internal/chrono/chrono.go b/internal/chrono/chrono.go new file mode 100644 index 0000000..370821e --- /dev/null +++ b/internal/chrono/chrono.go @@ -0,0 +1,93 @@ +package chrono + +import ( + "bufio" + "fmt" + "os" + "path/filepath" + "regexp" + "time" +) + +type ChronoEntry struct { + Date, Time, Action string +} + +type ParsedChronoEntry struct { + StartTime time.Time + Action string + Duration string +} + +func Chrono() { + // Return path of an executable + exPath, err := os.Executable() + if err != nil { + panic(err) + } + exDir := filepath.Dir(exPath) + fmt.Println(exDir) + // Return path of the current directory + path, err := os.Getwd() + if err != nil { + panic(err) + } + // Join paths + textFilePath := filepath.Join(path, "chrono.txt") + // Read file with chrono data + readFile, err := os.Open(textFilePath) + if err != nil { + panic(err) + } + defer readFile.Close() + + fileScanner := bufio.NewScanner(readFile) + fileScanner.Split(bufio.ScanLines) + var fileLines []string + for fileScanner.Scan() { + fileLines = append(fileLines, fileScanner.Text()) + } + // Prepare slice for data + parse_result := make([]ChronoEntry, 0) + result := make([]ParsedChronoEntry, 0) + r := regexp.MustCompile( + `(?P\d{2}\s\w*\s\d{4})\s+at\s+(?P