Documentation
¶
Overview ¶
Package notation can be used to print (or sprint) Go objects with optional wrapping (and indentation) and optional type information.
Example ¶
package main
import (
"os"
"code.squareroundforest.org/arpio/notation"
)
type bike struct {
frame frame
driveTrain driveTrain
wheels []wheel
handlebar handlebar
saddle saddle
}
type frame struct {
fork fork
saddlePost saddlePost
bottomBracket *bracket
frontDerailleur *derailleur
rearDerailleur *derailleur
rearBrake *brake
rearWheel *wheel
}
type driveTrain struct {
bottomBracket bracket
crank crank
brakes []brake
derailleurs []derailleur
cassette cassette
chain chain
levers []lever
}
type wheel struct {
size float64
cassette *cassette
}
type handlebar struct{ levers []*lever }
type saddle struct{}
type fork struct {
wheel *wheel
handlebar *handlebar
frontBrake *brake
}
type saddlePost struct{ saddle *saddle }
type bracket struct{ crank *crank }
type derailleur struct{ gears int }
type brake struct{ discSize float64 }
type crank struct {
wheels int
chain *chain
}
type cassette struct {
wheels int
chain *chain
}
type chain struct{}
type lever struct{ withShift bool }
func main() {
b := bike{
frame: frame{
fork: fork{},
saddlePost: saddlePost{},
},
driveTrain: driveTrain{
bottomBracket: bracket{},
crank: crank{wheels: 2},
brakes: []brake{{discSize: 160}, {discSize: 140}},
derailleurs: []derailleur{{gears: 2}, {gears: 11}},
cassette: cassette{wheels: 11},
chain: chain{},
levers: []lever{{true}, {true}},
},
wheels: []wheel{{size: 700}, {size: 700}},
handlebar: handlebar{},
saddle: saddle{},
}
b.frame.fork.wheel = &b.wheels[0]
b.frame.fork.handlebar = &b.handlebar
b.frame.fork.handlebar.levers = []*lever{&b.driveTrain.levers[0], &b.driveTrain.levers[1]}
b.frame.fork.frontBrake = &b.driveTrain.brakes[0]
b.frame.saddlePost.saddle = &b.saddle
b.frame.bottomBracket = &b.driveTrain.bottomBracket
b.frame.frontDerailleur = &b.driveTrain.derailleurs[0]
b.frame.rearDerailleur = &b.driveTrain.derailleurs[1]
b.frame.rearBrake = &b.driveTrain.brakes[1]
b.frame.rearWheel = &b.wheels[1]
b.frame.bottomBracket.crank = &b.driveTrain.crank
b.frame.bottomBracket.crank.chain = &b.driveTrain.chain
b.frame.rearWheel.cassette = &b.driveTrain.cassette
b.frame.rearWheel.cassette.chain = &b.driveTrain.chain
notation.Fprintw(os.Stdout, b)
}
Output: { frame: { fork: { wheel: {size: 700, cassette: nil}, handlebar: { levers: []{ {withShift: true}, {withShift: true}, }, }, frontBrake: {discSize: 160}, }, saddlePost: {saddle: {}}, bottomBracket: {crank: {wheels: 2, chain: {}}}, frontDerailleur: {gears: 2}, rearDerailleur: {gears: 11}, rearBrake: {discSize: 140}, rearWheel: { size: 700, cassette: {wheels: 11, chain: {}}, }, }, driveTrain: { bottomBracket: {crank: {wheels: 2, chain: {}}}, crank: {wheels: 2, chain: {}}, brakes: []{{discSize: 160}, {discSize: 140}}, derailleurs: []{{gears: 2}, {gears: 11}}, cassette: {wheels: 11, chain: {}}, chain: {}, levers: []{{withShift: true}, {withShift: true}}, }, wheels: []{ {size: 700, cassette: nil}, {size: 700, cassette: {wheels: 11, chain: {}}}, }, handlebar: {levers: []{{withShift: true}, {withShift: true}}}, saddle: {}, }
Example (Array) ¶
package main
import (
"os"
"code.squareroundforest.org/arpio/notation"
)
func main() {
a := [...]int{1, 2, 3}
notation.Fprint(os.Stdout, a)
}
Output: [3]{1, 2, 3}
Example (Bytes) ¶
package main
import (
"os"
"code.squareroundforest.org/arpio/notation"
)
func main() {
b := []byte(
`The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The
quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown
fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps
over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy
dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The
quick brown fox jumps over the lazy dog.`,
)
notation.Fprintwt(os.Stdout, b)
}
Output: []byte{ 54 68 65 20 71 75 69 63 6b 20 62 72 6f 77 6e 20 66 6f 78 20 6a 75 6d 70 73 20 6f 76 65 72 20 74 68 65 20 6c 61 7a 79 20 64 6f 67 2e 20 54 68 65 20 71 75 69 63 6b 20 62 72 6f 77 6e 20 66 6f 78 20 6a 75 6d 70 73 20 6f 76 65 72 20 74 68 65 20 6c 61 7a 79 20 64 6f 67 2e 20 54 68 65 0a 71 75 69 63 6b 20 62 72 6f 77 6e 20 66 6f 78 20 6a 75 6d 70 73 20 6f 76 65 72 20 74 68 65 20 6c 61 7a 79 20 64 6f 67 2e 20 54 68 65 20 71 75 69 63 6b 20 62 72 6f 77 6e 20 66 6f 78 20 6a 75 6d 70 73 20 6f 76 65 72 20 74 68 65 20 6c 61 7a 79 20 64 6f 67 2e 20 54 68 65 20 71 75 69 63 6b 20 62 72 6f 77 6e 0a 66 6f 78 20 6a 75 6d 70 73 20 6f 76 65 72 20 74 68 65 20 6c 61 7a 79 20 64 6f 67 2e 20 54 68 65 20 71 75 69 63 6b 20 62 72 6f 77 6e 20 66 6f 78 20 6a 75 6d 70 73 20 6f 76 65 72 20 74 68 65 20 6c 61 7a 79 20 64 6f 67 2e 20 54 68 65 20 71 75 69 63 6b 20 62 72 6f 77 6e 20 66 6f 78 20 6a 75 6d 70 73 0a 6f 76 65 72 20 74 68 65 20 6c 61 7a 79 20 64 6f 67 2e 20 54 68 65 20 71 75 69 63 6b 20 62 72 6f 77 6e 20 66 6f 78 20 6a 75 6d 70 73 20 6f 76 65 72 20 74 68 65 20 6c 61 7a 79 20 64 6f 67 2e 20 54 68 65 20 71 75 69 63 6b 20 62 72 6f 77 6e 20 66 6f 78 20 6a 75 6d 70 73 20 6f 76 65 72 20 74 68 65 20 6c 61 7a 79 0a 64 6f 67 2e 20 54 68 65 20 71 75 69 63 6b 20 62 72 6f 77 6e 20 66 6f 78 20 6a 75 6d 70 73 20 6f 76 65 72 20 74 68 65 20 6c 61 7a 79 20 64 6f 67 2e 20 54 68 65 20 71 75 69 63 6b 20 62 72 6f 77 6e 20 66 6f 78 20 6a 75 6d 70 73 20 6f 76 65 72 20 74 68 65 20 6c 61 7a 79 20 64 6f 67 2e 20 54 68 65 0a 71 75 69 63 6b 20 62 72 6f 77 6e 20 66 6f 78 20 6a 75 6d 70 73 20 6f 76 65 72 20 74 68 65 20 6c 61 7a 79 20 64 6f 67 2e }
Example (Cyclic_reference) ¶
package main
import (
"os"
"code.squareroundforest.org/arpio/notation"
)
func main() {
l := []interface{}{"foo"}
l[0] = l
notation.Fprint(os.Stdout, l)
}
Output: r0=[]{r0}
Example (Function) ¶
package main
import (
"os"
"code.squareroundforest.org/arpio/notation"
)
func main() {
f := func(int) int { return 42 }
notation.Fprint(os.Stdout, f)
}
Output: func()
Example (Function_signature) ¶
package main
import (
"os"
"code.squareroundforest.org/arpio/notation"
)
func main() {
f := func(int) int { return 42 }
notation.Fprintt(os.Stdout, f)
}
Output: func(int) int
Example (Int) ¶
package main
import (
"os"
"code.squareroundforest.org/arpio/notation"
)
func main() {
i := 42
notation.Fprintt(os.Stdout, i)
}
Output: 42
Example (Long_string) ¶
package main
import (
"os"
"code.squareroundforest.org/arpio/notation"
)
func main() {
s := `The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The
quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown
fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps
over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy
dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The
quick brown fox jumps over the lazy dog.`
notation.Fprintw(os.Stdout, s)
}
Output: `The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.`
Example (Maps_sorted_by_keys) ¶
package main
import (
"os"
"code.squareroundforest.org/arpio/notation"
)
func main() {
m := map[string]int{"b": 1, "c": 2, "a": 3}
notation.Fprint(os.Stdout, m)
}
Output: map{"a": 3, "b": 1, "c": 2}
Example (Named_type) ¶
package main
import (
"os"
"code.squareroundforest.org/arpio/notation"
)
func main() {
type t struct{ foo int }
v := t{42}
notation.Fprintt(os.Stdout, v)
}
Output: t{foo: 42}
Example (Short_string) ¶
package main
import (
"os"
"code.squareroundforest.org/arpio/notation"
)
func main() {
s := `foobar
baz`
notation.Fprintw(os.Stdout, s)
}
Output: "foobar\nbaz"
Example (Slice) ¶
package main
import (
"os"
"code.squareroundforest.org/arpio/notation"
)
func main() {
l := []int{1, 2, 3}
notation.Fprint(os.Stdout, l)
}
Output: []{1, 2, 3}
Example (Type_inferred) ¶
package main
import (
"os"
"code.squareroundforest.org/arpio/notation"
)
func main() {
v := []struct{ foo int }{{42}, {84}}
notation.Fprintt(os.Stdout, v)
}
Output: []struct{foo int}{{foo: 42}, {foo: 84}}
Example (Unnamed) ¶
package main
import (
"os"
"code.squareroundforest.org/arpio/notation"
)
func main() {
v := struct{ foo int }{42}
notation.Fprintt(os.Stdout, v)
}
Output: struct{foo int}{foo: 42}
Index ¶
- func Fprint(w io.Writer, v ...interface{}) (int, error)
- func Fprintln(w io.Writer, v ...interface{}) (int, error)
- func Fprintlnt(w io.Writer, v ...interface{}) (int, error)
- func Fprintlnv(w io.Writer, v ...interface{}) (int, error)
- func Fprintlnw(w io.Writer, v ...interface{}) (int, error)
- func Fprintlnwt(w io.Writer, v ...interface{}) (int, error)
- func Fprintlnwv(w io.Writer, v ...interface{}) (int, error)
- func Fprintt(w io.Writer, v ...interface{}) (int, error)
- func Fprintv(w io.Writer, v ...interface{}) (int, error)
- func Fprintw(w io.Writer, v ...interface{}) (int, error)
- func Fprintwt(w io.Writer, v ...interface{}) (int, error)
- func Fprintwv(w io.Writer, v ...interface{}) (int, error)
- func Print(v ...interface{}) (int, error)
- func Println(v ...interface{}) (int, error)
- func Printlnt(v ...interface{}) (int, error)
- func Printlnv(v ...interface{}) (int, error)
- func Printlnw(v ...interface{}) (int, error)
- func Printlnwt(v ...interface{}) (int, error)
- func Printlnwv(v ...interface{}) (int, error)
- func Printt(v ...interface{}) (int, error)
- func Printv(v ...interface{}) (int, error)
- func Printw(v ...interface{}) (int, error)
- func Printwt(v ...interface{}) (int, error)
- func Printwv(v ...interface{}) (int, error)
- func Sprint(v ...interface{}) string
- func Sprintt(v ...interface{}) string
- func Sprintv(v ...interface{}) string
- func Sprintw(v ...interface{}) string
- func Sprintwt(v ...interface{}) string
- func Sprintwv(v ...interface{}) string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Fprint ¶
Fprint prints the provided objects to the provided writer. When multiple objects are printed, they'll be separated by a space.
func Fprintln ¶
Fprintln prints the provided objects to the provided writer with a closing newline. When multiple objects are printed, they'll be separated by a space.
func Fprintlnt ¶
Fprintlnt prints the provided objects to the provided writer with a closing newline, with moderate type information. When multiple objects are printed, they'll be separated by a space.
func Fprintlnv ¶
Fprintv prints the provided objects to the provided writer with a closing newline, with verbose type information. When multiple objects are printed, they'll be separated by a space.
func Fprintlnw ¶
Fprintlnw prints the provided objects to the provided writer with a closing newline, with wrapping (and indentation) where necessary. When multiple objects are printed, they'll be separated by a newline.
func Fprintlnwt ¶
Fprintlnwt prints the provided objects to the provided writer with a closing newline, with wrapping (and indentation) where necessary, and with moderate type information. When multiple objects are printed, they'll be separated by a newline.
func Fprintlnwv ¶
Fprintlnwv prints the provided objects to the provided writer with a closing newline, with wrapping (and indentation) where necessary, and with verbose type information. When multiple objects are printed, they'll be separated by a newline.
func Fprintt ¶
Fprintt prints the provided objects to the provided writer with moderate type information. When multiple objects are printed, they'll be separated by a space.
func Fprintv ¶
Fprintv prints the provided objects to the provided writer with verbose type information. When multiple objects are printed, they'll be separated by a space.
func Fprintw ¶
Fprintw prints the provided objects to the provided writer, with wrapping (and indentation) where necessary. When multiple objects are printed, they'll be separated by a newline.
func Fprintwt ¶
Fprintwt prints the provided objects to the provided writer, with wrapping (and indentation) where necessary, and with moderate type information. When multiple objects are printed, they'll be separated by a newline.
func Fprintwv ¶
Fprintwv prints the provided objects to the provided writer, with wrapping (and indentation) where necessary, and with verbose type information. When multiple objects are printed, they'll be separated by a newline.
func Print ¶
Print prints the provided objects to stderr. When multiple objects are printed, they'll be separated by a space.
func Println ¶
Println prints the provided objects to stderr with a closing newline. When multiple objects are printed, they'll be separated by a space.
func Printlnt ¶
Printlnt prints the provided objects to stderr with a closing newline, and with moderate type information. When multiple objects are printed, they'll be separated by a space.
func Printlnv ¶
Printlnv prints the provided objects to stderr with a closing newline, and with verbose type information. When multiple objects are printed, they'll be separated by a space.
func Printlnw ¶
Printlnw prints the provided objects to stderr with a closing newline, with wrapping (and indentation) where necessary. When multiple objects are printed, they'll be separated by a newline.
func Printlnwt ¶
Printlnwt prints the provided objects to stderr with a closing newline, with wrapping (and indentation) where necessary, and with moderate type information. When multiple objects are printed, they'll be separated by a newline.
func Printlnwv ¶
Printlnwv prints the provided objects to stderr with a closing newline, with wrapping (and indentation) where necessary, and with verbose type information. When multiple objects are printed, they'll be separated by a newline.
func Printt ¶
Printt prints the provided objects to stderr with moderate type information. When multiple objects are printed, they'll be separated by a space.
func Printv ¶
Printv prints the provided objects to stderr with verbose type information. When multiple objects are printed, they'll be separated by a space.
func Printw ¶
Printw prints the provided objects to stderr, with wrapping (and indentation) where necessary. When multiple objects are printed, they'll be separated by a newline.
func Printwt ¶
Printwt prints the provided objects to stderr, with wrapping (and indentation) where necessary, and with moderate type information. When multiple objects are printed, they'll be separated by a newline.
func Printwv ¶
Printwv prints the provided objects to stderr, with wrapping (and indentation) where necessary, and with verbose type information. When multiple objects are printed, they'll be separated by a newline.
func Sprint ¶
func Sprint(v ...interface{}) string
Sprint returns the string representation of the Go objects. When multiple objects are provided, they'll be seprated by a space.
func Sprintt ¶
func Sprintt(v ...interface{}) string
Sprintt returns the string representation of the Go objects, with moderate type information. When multiple objects are provided, they'll be seprated by a space.
func Sprintv ¶
func Sprintv(v ...interface{}) string
Sprintv returns the string representation of the Go objects, with verbose type information. When multiple objects are provided, they'll be seprated by a space.
func Sprintw ¶
func Sprintw(v ...interface{}) string
Sprintw returns the string representation of the Go objects, with wrapping (and indentation) where necessary. When multiple objects are provided, they'll be seprated by a newline.
Types ¶
This section is empty.