codewriter

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package codewriter is a simple helper for writing out source code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

func New

func New(pkg string) *Writer

func (*Writer) Body

func (c *Writer) Body() string

Body returns the body of the code, without the package declaration and imports.

func (*Writer) Bytes

func (c *Writer) Bytes() []byte

Bytes returns the self-contained complete generated code.

func (*Writer) Import

func (c *Writer) Import(pkgs ...string)

Import adds an import to the generated code.

func (*Writer) In

func (c *Writer) In(fn func(w *Writer))

In calls "fn" with a Writer that is indented one level.

func (*Writer) Indent

func (c *Writer) Indent()

Indent writes the current indent level without a newline.

func (*Writer) L

func (c *Writer) L(format string, args ...any)

L writes a newline-terminated string to the writer.

func (*Writer) Pop

func (c *Writer) Pop() *Writer

Pop returns a Writer unindented one level.

func (*Writer) Prelude added in v0.4.0

func (c *Writer) Prelude() *Writer

func (*Writer) Push

func (c *Writer) Push() *Writer

Push returns a Writer indented one level.

func (*Writer) String

func (c *Writer) String() string

String returns the self-contained complete generated code.

func (*Writer) Trailer

func (c *Writer) Trailer() *Writer

Trailer returns a Writer that will be appended to the end of the code.

Useful for writing out helper functions and other globals.

func (*Writer) W

func (c *Writer) W(format string, args ...any)

W writes a formatted string directly to the writer without indentation or newline.

Jump to

Keyboard shortcuts

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