From 61c73803c7be37e688c91cd190ae4273c655dbb8 Mon Sep 17 00:00:00 2001 From: balki <3070606-balki@users.noreply.gitlab.com> Date: Tue, 3 May 2022 17:48:42 -0400 Subject: [PATCH] cleanupe --- TODO.md | 8 ++- app/download.go | 1 - exp/cron/cron.go | 20 -------- exp/csv/csv.go | 0 exp/csv/main.go | 41 --------------- exp/csvw/main.go | 30 ----------- exp/exec/exec.go | 19 ------- exp/file/file.go | 29 ----------- exp/funint/main.go | 35 ------------- exp/log/main.go | 17 ------- exp/proxy/main.go | 27 ---------- exp/ref/main.go | 35 ------------- exp/slice/main.go | 14 ------ exp/tor/proxy.go | 30 ----------- exp/xml/xml.go | 121 --------------------------------------------- log/exp.go | 1 - 16 files changed, 6 insertions(+), 422 deletions(-) delete mode 100644 app/download.go delete mode 100644 exp/cron/cron.go delete mode 100644 exp/csv/csv.go delete mode 100644 exp/csv/main.go delete mode 100644 exp/csvw/main.go delete mode 100644 exp/exec/exec.go delete mode 100644 exp/file/file.go delete mode 100644 exp/funint/main.go delete mode 100644 exp/log/main.go delete mode 100644 exp/proxy/main.go delete mode 100644 exp/ref/main.go delete mode 100644 exp/slice/main.go delete mode 100644 exp/tor/proxy.go delete mode 100644 exp/xml/xml.go delete mode 100644 log/exp.go diff --git a/TODO.md b/TODO.md index 2afc75f..5d319fd 100644 --- a/TODO.md +++ b/TODO.md @@ -11,13 +11,16 @@ https://gist.github.com/zdebra/10f0e284c4672e99f0cb767298f20c11 * ✓ First Run skip all but first n * ✓ Folder creation -* ✓ Wrap content inside item +* ✓ Wrap content inside item ⚠️ atom calls it entry +* ✓ Implement atom +* ✓ Cleanup * Change flags to os.Args[1] for config path -* Cleanup * Make Rhash optional ## Issues * ✓ Last record is not written fully to csv: *Fixed*. Had to Flush writer +* Wrap entry content properly +* Some random chars in request/response data ## MVP 2 * Podcasts @@ -52,3 +55,4 @@ ### Log * Log to file * unit testing logs? +* Use go-logr Logger interface diff --git a/app/download.go b/app/download.go deleted file mode 100644 index 4879f7a..0000000 --- a/app/download.go +++ /dev/null @@ -1 +0,0 @@ -package app diff --git a/exp/cron/cron.go b/exp/cron/cron.go deleted file mode 100644 index f972e24..0000000 --- a/exp/cron/cron.go +++ /dev/null @@ -1,20 +0,0 @@ -package main - -import ( - "fmt" - "log" - "time" - - "github.com/robfig/cron/v3" -) - -func main() { - fmt.Println("vim-go") - - s, err := cron.ParseStandard("@daily") - if err != nil { - log.Fatal(err) - } - - fmt.Println(s.Next(time.Now())) -} diff --git a/exp/csv/csv.go b/exp/csv/csv.go deleted file mode 100644 index e69de29..0000000 diff --git a/exp/csv/main.go b/exp/csv/main.go deleted file mode 100644 index 44e1a69..0000000 --- a/exp/csv/main.go +++ /dev/null @@ -1,41 +0,0 @@ -package main - -import ( - "bytes" - "encoding/csv" - "fmt" - "time" - - "gopkg.in/yaml.v3" -) - -func main() { - fmt.Println("vim-go") - fb := bytes.NewReader(nil) - cr := csv.NewReader(fb) - records, err := cr.ReadAll() - fmt.Println(records, err) - fmt.Println(time.Now().String()) - yesterday := time.Now().Add(-24 * time.Hour) - m := map[string]time.Time{ - "Bala": time.Now(), - "Linus": yesterday, - } - data, _ := yaml.Marshal(&m) - fmt.Printf("%s\n", data) - //format := "2022-05-01T15:08:20.593630746-04:00" - format := "2006-01-02T15:04:05.999999999-07:00" - fmt.Println("============") - fmt.Println(yesterday.Format(format)) - fmt.Println("============") - fmt.Println(yesterday.GoString()) -} - -/* - -Linus: - -============ -2022-04-30T15:14:40.302916106-04:00 -2022-04-30T15:14:40.302916106-04:00 -*/ diff --git a/exp/csvw/main.go b/exp/csvw/main.go deleted file mode 100644 index 3380d8f..0000000 --- a/exp/csvw/main.go +++ /dev/null @@ -1,30 +0,0 @@ -package main - -import ( - "bytes" - "encoding/csv" - "fmt" - "io" -) - -func main() { - fmt.Println("vim-go") - var b bytes.Buffer - writer := csv.NewWriter(&b) - err := writer.Write([]string{ - "foo", - "bar", - "blah", - }) - if err != nil { - panic(err) - } - writer.Flush() - b.WriteString("Hello World") - content, err := io.ReadAll(&b) - if err != nil { - panic(err) - } - fmt.Printf("%s\n", content) - fmt.Println("bye") -} diff --git a/exp/exec/exec.go b/exp/exec/exec.go deleted file mode 100644 index 15c859a..0000000 --- a/exp/exec/exec.go +++ /dev/null @@ -1,19 +0,0 @@ -package main - -import ( - "fmt" - "os/exec" -) - -func main() { - fmt.Println("vim-go") - c := exec.Command("./script.sh") - op, err := c.Output() - if err != nil { - fmt.Println(err) - exitErr := err.(*exec.ExitError) - fmt.Printf("hello %s\n", exitErr.Stderr) - } else { - fmt.Printf("%s", op) - } -} diff --git a/exp/file/file.go b/exp/file/file.go deleted file mode 100644 index 3ca5613..0000000 --- a/exp/file/file.go +++ /dev/null @@ -1,29 +0,0 @@ -package main - -import ( - "fmt" - "log" - "os" -) - -func main() { - fmt.Println("vim-go") - f, err := os.Create("./lsdkj/lfksdjf") - if err != nil { - log.Panicln(err) - } - err = f.Close() - if err != nil { - log.Panicln(err) - } - log.Println("created") - /* - data, err := os.ReadFile("./foo/notexist") - if err == nil { - fmt.Println(data) - } else if errors.Is(err, os.ErrNotExist) { - fmt.Printf("not exist: %v\n", err) - } - fmt.Printf("err: %v\n", err) - */ -} diff --git a/exp/funint/main.go b/exp/funint/main.go deleted file mode 100644 index b053f3e..0000000 --- a/exp/funint/main.go +++ /dev/null @@ -1,35 +0,0 @@ -package main - -import ( - "fmt" - "net" -) - -type Foo interface { - Bar() -} - -func bar() { - fmt.Println("bar") -} - -func run(f Foo) { - f.Bar() -} - -type t struct { - Bar func() -} - -type t2 struct { -} - -func (t t2) Bar() { - bar() -} - -func main() { - run(t2{}) - var d net.Dialer - d.Cancel -} diff --git a/exp/log/main.go b/exp/log/main.go deleted file mode 100644 index 50489b5..0000000 --- a/exp/log/main.go +++ /dev/null @@ -1,17 +0,0 @@ -package main - -import ( - "fmt" - - "go.balki.me/tss/log" - "go.uber.org/zap" -) - -func main() { - fmt.Println("vim-go") - log.Info("does this work", "trycount", 1) - // fmt.Sprint("ldskfjdsice") - s := zap.S() - s.Warnw("How does this look", "trycount", 2) - s.Sync() -} diff --git a/exp/proxy/main.go b/exp/proxy/main.go deleted file mode 100644 index 36941a4..0000000 --- a/exp/proxy/main.go +++ /dev/null @@ -1,27 +0,0 @@ -package main - -import ( - "fmt" - "io" - "log" - "net/http" - - "go.balki.me/tss/proxy" -) - -func main() { - trans, err := proxy.GetTransport("socks5://unix/run/tor/socks") - client := &http.Client{ - Transport: trans, - } - res, err := client.Get("https://ip.balki.me") - if err != nil { - log.Panicln(err) - } - data, err := io.ReadAll(res.Body) - if err != nil { - log.Panicln(err) - } - fmt.Printf("status: %v, data: %s\n", res.Status, data) - fmt.Printf("%#v\n", client.Transport) -} diff --git a/exp/ref/main.go b/exp/ref/main.go deleted file mode 100644 index 6a1a648..0000000 --- a/exp/ref/main.go +++ /dev/null @@ -1,35 +0,0 @@ -package main - -import "fmt" - -type dummy struct { - name string -} - -func main() { - fmt.Println("vim-go") - dummies := []dummy{ - dummy{"foo"}, - dummy{"bar"}, - dummy{"baz"}, - } - - for i, _ := range dummies { - dum := &dummies[i] - dum.name = "hello" - } - - for _, dum := range dummies { - fmt.Println(dum.name) - } - - foo() - -} - -func foo() { - var stuff []string - defer fmt.Println(stuff) - stuff = append(stuff, "foo") - stuff = append(stuff, "bar") -} diff --git a/exp/slice/main.go b/exp/slice/main.go deleted file mode 100644 index 1ad910b..0000000 --- a/exp/slice/main.go +++ /dev/null @@ -1,14 +0,0 @@ -package main - -import "fmt" - -func main() { - var arr []int - for i := 0; i < 10; i++ { - arr = append(arr, i) - } - fmt.Println(arr) - fmt.Println(arr[:0], arr[0:]) - fmt.Println(arr[:4], arr[4:]) - fmt.Println(arr[:15], arr[15:]) -} diff --git a/exp/tor/proxy.go b/exp/tor/proxy.go deleted file mode 100644 index f2bb32e..0000000 --- a/exp/tor/proxy.go +++ /dev/null @@ -1,30 +0,0 @@ -package main - -import ( - "io" - "log" - "net/http" - "net/url" -) - -func main() { - //proxyUrl, err := url.Parse("socks5://unix//run/tor/socks") - proxyUrl, err := url.Parse("socks5://127.0.0.1:9050/#Foo") - if err != nil { - log.Panicln(err) - } - log.Println(len(proxyUrl.Path)) - client := http.Client{ - Transport: &http.Transport{ - Proxy: func(*http.Request) (*url.URL, error) { return proxyUrl, nil }, - }, - } - // res, err := client.Get("http://hz3ppwwc55ccokb63r4ou7za45c5raodu23absuregtqo5ha3h37gfyd.onion") - res, err := client.Get("https://ip.balki.me") - if err != nil { - log.Panicln(err) - } - - data, err := io.ReadAll(res.Body) - log.Printf("data: %s, status: %s\n", data, res.Status) -} diff --git a/exp/xml/xml.go b/exp/xml/xml.go deleted file mode 100644 index a1875ac..0000000 --- a/exp/xml/xml.go +++ /dev/null @@ -1,121 +0,0 @@ -package main - -import ( - "bytes" - "encoding/csv" - "encoding/xml" - "fmt" - "io" - "log" - "os" - "strings" - "time" -) - -/* - XMLName xml.Name `xml:"person"` - FirstName string `xml:"firstname"` - Parents interface{} `xml:"parent"` -*/ - -type Item struct { - Title string `xml:"title"` - Link string `xml:"link"` - Author string `xml:"author"` - Guid string `xml:"guid"` - Description string `xml:"description"` - Content string `xml:",innerxml"` -} - -func main() { - fmt.Println("hello go") - foo() - if 1 == 1 { - return - } - data, err := os.ReadFile("/home/balki/projects/tss/w.tmp/ounapuu.xml") - if err != nil { - log.Fatal(err) - } - - v := struct { - Items []Item `xml:"channel>item"` - }{} - - err = xml.Unmarshal(data, &v) - if err != nil { - log.Fatal(err) - } - - f, err := os.OpenFile("./data.csv", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) - - defer f.Close() - - if err != nil { - log.Fatal(err) - } - var b bytes.Buffer - b.WriteString("hello world") - csvw := csv.NewWriter(&b) - csvw.Write([]string{ - "date", - "link", - "info", - }) - - for index, item := range v.Items[:3] { - c := item.Content - fmt.Println(index, len(c), item.Title) - //fmt.Println(item.Content) - err = csvw.Write([]string{ - time.Now().String(), - item.Link, - strings.Replace(c, "\n", " ", -1), - }) - if err != nil { - panic(err) - } - /* - err = csvw.Write([]string{ - time.Now().String(), - "dummy.link", - "dummy content, lskdjf lksjdf lkjk", - }) - if err != nil { - panic(err) - } - */ - } - csvw.Flush() - err = f.Sync() - fmt.Println(err) - data2, err := io.ReadAll(&b) - fmt.Printf("data2: %s\n", data2) - fmt.Println(err) - // fmt.Println(v.Items[len(v.Items)-1].Content) -} -func foo() { - x := ` - - - Hello World - slkdfjdslk - - -` - s := struct { - Bar struct { - Link struct { - Href string `xml:"href,attr"` - } `xml:"link"` - Attr string `xml:"src,attr"` - Content string `xml:",innerxml"` - } `xml:"bar"` - }{} - - err := xml.Unmarshal([]byte(x), &s) - if err != nil { - log.Fatal(err) - } - fmt.Println(s.Bar.Link.Href) -} diff --git a/log/exp.go b/log/exp.go deleted file mode 100644 index 7330d54..0000000 --- a/log/exp.go +++ /dev/null @@ -1 +0,0 @@ -package log