Skip to content

Instantly share code, notes, and snippets.

@Subi
Last active December 24, 2021 02:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Subi/a3e0f103760656d41b797b9957b2d85f to your computer and use it in GitHub Desktop.
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
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
}
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