Skip to content

Instantly share code, notes, and snippets.

@Subi
Last active December 24, 2021 02:22
Show Gist options
  • Select an option

  • Save Subi/a3e0f103760656d41b797b9957b2d85f to your computer and use it in GitHub Desktop.

Select an option

Save Subi/a3e0f103760656d41b797b9957b2d85f to your computer and use it in GitHub Desktop.

Revisions

  1. Subi revised this gist Dec 24, 2021. No changes.
  2. Subi created this gist Dec 24, 2021.
    39 changes: 39 additions & 0 deletions formatter.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    package formatter

    import (
    "fmt"
    "io/ioutil"
    "log"
    "strings"
    )

    type Formatter interface {
    Read() string
    Format(string) string
    }

    type proxyFormatter struct {
    Proxies []string
    }

    func NewProxyFormatter() Formatter {
    return &proxyFormatter{}
    }

    func (p *proxyFormatter) Read() string {
    content, err := ioutil.ReadFile("proxies.txt")

    if err != nil {
    log.Fatalln("Error occurred reading proxies.txt file", err.Error())
    }
    return string(content)
    }

    func (p *proxyFormatter) Format(content string) (res string) {
    proxies := strings.Split(content, "\n")

    for _, proxy := range proxies {
    res += fmt.Sprintf("- %s \n", proxy)
    }
    return
    }
    15 changes: 15 additions & 0 deletions main.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    package main

    import (
    "log"
    f "proxyformatter/formatter"
    )

    func main() {
    pf := f.NewProxyFormatter()

    resp := pf.Read()
    results := pf.Format(resp)

    log.Println(results)
    }