printgo

package module
v0.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 10, 2026 License: MIT Imports: 6 Imported by: 8

README

GitHub Workflow Status (branch) GoDoc Coverage Status Supported Go Versions GitHub Release Go Report Card

printgo

printgo lets you print strings piece-by-piece, then get the whole text at once.


CHINESE README

中文说明

Main Features

📝 Content Accumulation - Print strings piece-by-piece, get whole text at once 🔄 Two Implementations - PTX (bytes.Buffer) and PTS (strings.Builder) ✨ Fmt-Style Methods - Print, Println, Printf, Fprintf with known interface ⚡ Auto Exception Handling - Integrated exception handling with done/must/rese packages 🎯 Simple API - Quick to use with compact code

Installation

go get github.com/yylego/printgo

Usage

Basic PTX Example
package main

import (
	"fmt"

	"github.com/yylego/printgo"
)

func main() {
	// Create PTX based on bytes.Buffer
	ptx := printgo.NewPTX()

	// Print function piece-by-piece
	ptx.Println("func Add(a, b int) int {")
	ptx.Println("\treturn a + b")
	ptx.Println("}")

	// Get the complete function code
	result := ptx.String()
	fmt.Println(result)
}

⬆️ Source: Source

Basic PTS Example
package main

import (
	"fmt"

	"github.com/yylego/printgo"
)

func main() {
	// Create PTS based on strings.Builder
	pts := printgo.NewPTS()

	// Build struct definition piece-by-piece
	pts.Println("type Person struct {")
	pts.Printf("\tName string\n")
	pts.Printf("\tAge  int\n")
	pts.Println("}")

	// Get the complete struct code
	result := pts.String()
	fmt.Println(result)
}

⬆️ Source: Source

Examples

PTX vs PTS

PTX (bytes.Buffer):

ptx := printgo.NewPTX()
ptx.Println("Using bytes.Buffer")

PTS (strings.Builder):

pts := printgo.NewPTS()
pts.Println("Using strings.Builder")
Format Printing

Printf:

ptx := printgo.NewPTX()
ptx.Printf("Name: %s, Age: %d\n", "Alice", 30)

Fprintf:

pts := printgo.NewPTS()
pts.Fprintf("Total: %.2f", 123.456)

Printfln (format + newline):

ptx := printgo.NewPTX()
ptx.Printfln("Name: %s", "test")
ptx.Printfln("Age: %d", 18)

API Reference

PTX (bytes.Buffer based)
Method Description
NewPTX() Create new PTX instance
Print(args...) Print without newline
Println(args...) Print with newline
Printf(format, args...) Format and print
Fprintf(format, args...) Format and print
Printfln(format, args...) Format and print with newline
Fprintfln(format, args...) Format and print with newline
String() Get accumulated text
Bytes() Get accumulated bytes
PTS (strings.Builder based)
Method Description
NewPTS() Create new PTS instance
Print(args...) Print without newline
Println(args...) Print with newline
Printf(format, args...) Format and print
Fprintf(format, args...) Format and print
Printfln(format, args...) Format and print with newline
Fprintfln(format, args...) Format and print with newline
String() Get accumulated text

📄 License

MIT License - see LICENSE.


💬 Contact & Feedback

Contributions are welcome! Report bugs, suggest features, and contribute code:

  • 🐛 Mistake reports? Open an issue on GitHub with reproduction steps
  • 💡 Fresh ideas? Create an issue to discuss
  • 📖 Documentation confusing? Report it so we can improve
  • 🚀 Need new features? Share the use cases to help us understand requirements
  • Performance issue? Help us optimize through reporting slow operations
  • 🔧 Configuration problem? Ask questions about complex setups
  • 📢 Follow project progress? Watch the repo to get new releases and features
  • 🌟 Success stories? Share how this package improved the workflow
  • 💬 Feedback? We welcome suggestions and comments

🔧 Development

New code contributions, follow this process:

  1. Fork: Fork the repo on GitHub (using the webpage UI).
  2. Clone: Clone the forked project (git clone https://github.com/yourname/repo-name.git).
  3. Navigate: Navigate to the cloned project (cd repo-name)
  4. Branch: Create a feature branch (git checkout -b feature/xxx).
  5. Code: Implement the changes with comprehensive tests
  6. Testing: (Golang project) Ensure tests pass (go test ./...) and follow Go code style conventions
  7. Documentation: Update documentation to support client-facing changes
  8. Stage: Stage changes (git add .)
  9. Commit: Commit changes (git commit -m "Add feature xxx") ensuring backward compatible code
  10. Push: Push to the branch (git push origin feature/xxx).
  11. PR: Open a merge request on GitHub (on the GitHub webpage) with detailed description.

Please ensure tests pass and include relevant documentation updates.


🌟 Support

Welcome to contribute to this project via submitting merge requests and reporting issues.

Project Support:

  • Give GitHub stars if this project helps you
  • 🤝 Share with teammates and (golang) programming friends
  • 📝 Write tech blogs about development tools and workflows - we provide content writing support
  • 🌟 Join the ecosystem - committed to supporting open source and the (golang) development scene

Have Fun Coding with this package! 🎉🎉🎉


GitHub Stars

Stargazers

Documentation

Overview

Package printgo lets you print strings piece-by-piece, then get the whole text at once Wraps bytes.Buffer and strings.Builder with fmt-style print functions Use Print/Println/Printf to write content, get result with String() / Bytes()

printgo 包让你逐个打印字符串,最后一次性获取完整文本 包装 bytes.Buffer 和 strings.Builder,提供 fmt 风格的打印函数 使用 Print/Println/Printf 写入内容,通过 String() 或 Bytes() 获取结果

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PTS

type PTS struct{ strings.Builder }

PTS is strings.Builder-based type with fmt-style methods Accumulates printed content and provides String method to get output

PTS 是基于 strings.Builder 的类型,具有 fmt 风格的方法 累积打印内容并提供 String 方法获取输出

func NewPTS

func NewPTS() *PTS

NewPTS creates PTS based on strings.Builder Returns new instance to use with print operations

NewPTS 创建基于 strings.Builder 的 PTS 返回可用于打印操作的新实例

func (*PTS) Fprintf

func (pts *PTS) Fprintf(format string, args ...interface{}) (n int)

Fprintf formats and prints with custom format string Returns bytes written, panics on failure

Fprintf 使用自定义格式字符串格式化并打印 返回写入的字节数,出错时 panic

func (*PTS) Fprintfln

func (pts *PTS) Fprintfln(format string, args ...interface{}) (n int)

Fprintfln formats and prints with newline appended Returns bytes written, panics on failure

Fprintfln 格式化打印并追加换行符 返回写入的字节数,出错时 panic

func (*PTS) Print

func (pts *PTS) Print(args ...interface{}) (n int)

Print prints args without newline Returns bytes written, panics on failure

Print 打印参数不追加换行符 返回写入的字节数,出错时 panic

func (*PTS) Printf

func (pts *PTS) Printf(format string, args ...interface{}) (n int)

Printf formats and prints with custom format string Returns bytes written, panics on failure

Printf 使用自定义格式字符串格式化并打印 返回写入的字节数,出错时 panic

func (*PTS) Printfln

func (pts *PTS) Printfln(format string, args ...interface{}) (n int)

Printfln formats and prints with newline appended Returns bytes written, panics on failure

Printfln 格式化打印并追加换行符 返回写入的字节数,出错时 panic

func (*PTS) Println

func (pts *PTS) Println(args ...interface{}) (n int)

Println prints args with newline appended Returns bytes written, panics on failure

Println 打印参数并追加换行符 返回写入的字节数,出错时 panic

type PTX

type PTX struct{ bytes.Buffer }

PTX is bytes.Buffer-based type with fmt-style methods Accumulates printed content and provides String method to get output

PTX 是基于 bytes.Buffer 的类型,具有 fmt 风格的方法 累积打印内容并提供 String 方法获取输出

func NewPTX

func NewPTX() *PTX

NewPTX creates PTX based on bytes.Buffer Returns new instance to use with print operations

NewPTX 创建基于 bytes.Buffer 的 PTX 返回可用于打印操作的新实例

func (*PTX) Fprintf

func (ptx *PTX) Fprintf(format string, args ...interface{}) (n int)

Fprintf formats and prints with custom format string Returns bytes written, panics on failure

Fprintf 使用自定义格式字符串格式化并打印 返回写入的字节数,出错时 panic

func (*PTX) Fprintfln

func (ptx *PTX) Fprintfln(format string, args ...interface{}) (n int)

Fprintfln formats and prints with newline appended Returns bytes written, panics on failure

Fprintfln 格式化打印并追加换行符 返回写入的字节数,出错时 panic

func (*PTX) Print

func (ptx *PTX) Print(args ...interface{}) (n int)

Print prints args without newline Returns bytes written, panics on failure

Print 打印参数不追加换行符 返回写入的字节数,出错时 panic

func (*PTX) Printf

func (ptx *PTX) Printf(format string, args ...interface{}) (n int)

Printf formats and prints with custom format string Returns bytes written, panics on failure

Printf 使用自定义格式字符串格式化并打印 返回写入的字节数,出错时 panic

func (*PTX) Printfln

func (ptx *PTX) Printfln(format string, args ...interface{}) (n int)

Printfln formats and prints with newline appended Returns bytes written, panics on failure

Printfln 格式化打印并追加换行符 返回写入的字节数,出错时 panic

func (*PTX) Println

func (ptx *PTX) Println(args ...interface{}) (n int)

Println prints args with newline appended Returns bytes written, panics on failure

Println 打印参数并追加换行符 返回写入的字节数,出错时 panic

Directories

Path Synopsis
internal
demos/demo1x command
demos/demo2x command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL