fmt

package module
v0.0.0-...-e07a84e Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2020 License: AGPL-3.0 Imports: 4 Imported by: 0

README

fmtless: All the convenience of fmt without the bloat

by Cathal Garvey, ©2016, Released under the GNU AGPLv3 or later

Why Avoid fmt?

The fmt library is a super-rich way to present and parse data in your Go application. I love fmt; everyone loves fmt!

However, fmt is really big, adding a large premium to output binaries. For straight compilation to static binaries, this isn't usually a dealbreaker (cf. the success of Go overall).

However, in edge-cases, like embedding Go in storage-constrained devices, or shipping a collection of small apps in Go, or when transpiling to JS, the premium can be really costly. In my own experience, removing fmt from a GopherJS application removed 0.5Mb from the output Javascript, which can be a huge deal when shipping JS.

Most fmt imports seem to use it only for output, or for errors. So, fmtless is a toolkit for rapidly porting software using fmt for output and errors, hopefully only requiring a single-line change: instead of import "fmt", just do import "github.com/cathalgarvey/fmtless"!

fmtless also has mirrors of Go's standard libraries with fmt replaced with fmtless, to reduce binary size. Try switching over and see if it makes a difference to your application!

At present the included stdlibs in this repo are lifted directly from my local install. In the future I plan to have a script pull chosen libraries directly from the most recent tag/release of Go and converts them.

Usage

Right now, it's just replace fmt with github.com/cathalgarvey/fmtless. For stdlibs, likewise, it's just "prepend your stdlib imports with github.com/cathalgarvey/fmtless". Currently supported:

  • encoding/json (was only using stdlibs for errors)
  • encoding/xml (was only using stdlibs for errors)
  • net/url (was only using stdlibs for errors)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Errorf

func Errorf(format string, a ...interface{}) error

Errorf returns an error object for the given format and values.

func Print

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

Print formats using the default formats for its operands and writes to standard output. Spaces are added between operands when neither is a string. It returns the number of bytes written and any write error encountered.

func Printf

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

Printf prints a format string filled with the given values.

func Println

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

Println formats using the default formats for its operands and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.

func SRepeat

func SRepeat(char string, repeat int) string

SRepeat just repeats a character or string times <repeat>. DEPRICATED, just use strings.Repeat.

func Sprint

func Sprint(a ...interface{}) string

Sprint renders arguments in their default format ("%s"/"%d"/"%f"/"%U" for string/int/float/rune, respectively)

func Sprintf

func Sprintf(fmts string, args ...interface{}) string

Sprintf is a fmtless alternative to fmt.Sprintf that supports some of the most common subset of fmt usage.

func Sprintln

func Sprintln(a ...interface{}) string

Sprintln is just like Sprint but with a trailing newline.

Types

type Stringer

type Stringer interface {
	String() string
}

Stringer is implemented by any value that has a String method, which defines the “native” format for that value. The String method is used to print values passed as an operand to any format that accepts a string or to an unformatted printer such as Print.

Directories

Path Synopsis
encoding
json
Package json implements encoding and decoding of JSON objects as defined in RFC 4627.
Package json implements encoding and decoding of JSON objects as defined in RFC 4627.
xml
Package xml implements a simple XML 1.0 parser that understands XML name spaces.
Package xml implements a simple XML 1.0 parser that understands XML name spaces.
net
url
Package url parses URLs and implements query escaping.
Package url parses URLs and implements query escaping.

Jump to

Keyboard shortcuts

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