Last active
December 24, 2021 02:22
-
-
Save Subi/a3e0f103760656d41b797b9957b2d85f to your computer and use it in GitHub Desktop.
Read content from .txt file and output the results to be used with .yaml files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
f "proxyformatter/formatter" | |
) | |
func main() { | |
pf := f.NewProxyFormatter() | |
resp := pf.Read() | |
results := pf.Format(resp) | |
log.Println(results) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment