Help us shape the future of Go! Take the 2026 Go Developer Survey

fieldfmt

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: MIT Imports: 5 Imported by: 2

README

fieldfmt

Installation

$ go get github.com/gnue/fieldfmt

Usage

import "github.com/gnue/fieldfmt"

Examples

Fprintln
package main

import (
	"os"
	"text/tabwriter"

	"github.com/gnue/fieldfmt"
)

func main() {
	var s = struct {
		Id   int
		From string `field:"from,omitempty"`
		To   string `field:""`
	}{1, "foo", "bar"}

	w := tabwriter.NewWriter(os.Stdout, 0, 4, 1, ' ', 0)
	fieldfmt.Fprintln(w, &s, ":\t")
	w.Flush()
}

Output:

Id:   1
from: foo
To:   bar

Fprintln + tabwriter

Printf
package main

import (
	"github.com/gnue/fieldfmt"
)

func main() {
	var s = struct {
		Id   int
		From string `field:"from,omitempty"`
		To   string `field:""`
	}{1, "foo", "bar"}

	fieldfmt.Printf("%s: %v\n", &s)
}

Output:

Id: 1
from: foo
To: bar

Printf

include .go2readme/*.md

ex.

.go2readme/
├── 01_Contributing.md
├── 02_Author.md
└── 03_License.md

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Run test suite with the go test ./... command and confirm that it passes
  5. Run gofmt -s
  6. Push to the branch (git push origin my-new-feature)
  7. Create new Pull Request

Author

gnue

License

MIT

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fprintf

func Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error)

func Fprintln

func Fprintln(w io.Writer, value interface{}, sep string) (n int, err error)
Example

Fprintln + tabwriter

package main

import (
	"os"
	"text/tabwriter"

	"github.com/gnue/fieldfmt"
)

func main() {
	var s = struct {
		Id   int
		From string `field:"from,omitempty"`
		To   string `field:""`
	}{1, "foo", "bar"}

	w := tabwriter.NewWriter(os.Stdout, 0, 4, 1, ' ', 0)
	fieldfmt.Fprintln(w, &s, ":\t")
	w.Flush()
}
Output:

Id:   1
from: foo
To:   bar

func Printf

func Printf(format string, a ...interface{}) (n int, err error)
Example

Printf

package main

import (
	"github.com/gnue/fieldfmt"
)

func main() {
	var s = struct {
		Id   int
		From string `field:"from,omitempty"`
		To   string `field:""`
	}{1, "foo", "bar"}

	fieldfmt.Printf("%s: %v\n", &s)
}
Output:

Id: 1
from: foo
To: bar

func Println

func Println(value interface{}, sep string) (n int, err error)

Types

type Formatter

type Formatter interface {
	Format(k, v interface{}) string
}

type SimpleFormatter

type SimpleFormatter string

func (SimpleFormatter) Format

func (f SimpleFormatter) Format(k, v interface{}) string

type Writer

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

func NewWriter

func NewWriter(w io.Writer, fmtr Formatter, sep string) *Writer

func (*Writer) Print

func (w *Writer) Print(a ...interface{}) (n int, err error)

func (*Writer) Println

func (w *Writer) Println(a ...interface{}) (n int, err error)

func (*Writer) Write

func (w *Writer) Write(p []byte) (n int, err error)

func (*Writer) WriteByte

func (w *Writer) WriteByte(b byte) (n int, err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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