diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2023-09-21 01:53:59 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-21 01:53:59 +0300 |
| commit | 171e350e348afadb55967b9c13d5eadc7f7d2cf4 (patch) | |
| tree | 14ec93df8ccc1aca0cf453f826d46a402b09dc8f /pkg/writer/writer.go | |
| parent | define todos on packets (diff) | |
| download | sdp.go-171e350e348afadb55967b9c13d5eadc7f7d2cf4.tar.gz sdp.go-171e350e348afadb55967b9c13d5eadc7f7d2cf4.tar.bz2 sdp.go-171e350e348afadb55967b9c13d5eadc7f7d2cf4.zip | |
add strings builder, customize ALL outputs (#6)
Diffstat (limited to 'pkg/writer/writer.go')
| -rw-r--r-- | pkg/writer/writer.go | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/pkg/writer/writer.go b/pkg/writer/writer.go new file mode 100644 index 0000000..6b66e75 --- /dev/null +++ b/pkg/writer/writer.go | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | package writer | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "fmt" | ||
| 5 | "strings" | ||
| 6 | ) | ||
| 7 | |||
| 8 | var output strings.Builder | ||
| 9 | |||
| 10 | var temp strings.Builder | ||
| 11 | |||
| 12 | func Append(str string, a ...any) { | ||
| 13 | _, err := output.WriteString(fmt.Sprintf(str, a...)) | ||
| 14 | if err != nil { | ||
| 15 | output.WriteString(err.Error()) | ||
| 16 | } | ||
| 17 | } | ||
| 18 | |||
| 19 | func AppendLine(str string, a ...any) { | ||
| 20 | Append(str, a...) | ||
| 21 | output.WriteString("\n") | ||
| 22 | } | ||
| 23 | |||
| 24 | func GetString() string { | ||
| 25 | return output.String() | ||
| 26 | } | ||
| 27 | |||
| 28 | func TempAppend(str string, a ...any) { | ||
| 29 | _, err := temp.WriteString(fmt.Sprintf(str, a...)) | ||
| 30 | if err != nil { | ||
| 31 | temp.WriteString(err.Error()) | ||
| 32 | } | ||
| 33 | } | ||
| 34 | |||
| 35 | func TempAppendLine(str string, a ...any) { | ||
| 36 | TempAppend(str, a...) | ||
| 37 | temp.WriteString("\n") | ||
| 38 | } | ||
| 39 | |||
| 40 | func TempGetString() string { | ||
| 41 | return temp.String() | ||
| 42 | } | ||
| 43 | |||
| 44 | func AppendOutputFromTemp() { | ||
| 45 | output.WriteString(temp.String()) | ||
| 46 | temp.Reset() | ||
| 47 | } | ||