fmt

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2015 License: MIT, Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

The Cookoo `fmt` package provides utility wrappers for formatting text.

The commands in this package provide simple string formatting and printing at the command level.

For convenience, a basic "text/template" wrapper is included in this library, though a more robust "html/template" set of commands are provided in "github.com/Masterminds/cookoo/web".

Example usage:

reg.Route("test", "Test").
Does(Template, "out").
Using("template").WithDefault("{{.Hello}} {{.one}}").
Using("Hello").WithDefault("Hello").
Using("one").WithDefault(1)

Or

reg.Route("test", "Test").
Does(Sprintf, "out").
Using("format").WithDefault("%s %d").
Using("0").WithDefault("Hello").
Using("1").WithDefault(1)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Printf

func Printf(c cookoo.Context, params *cookoo.Params) (interface{}, cookoo.Interrupt)

Printf formats a string and then sends it to standard out.

This is a command wrapper for the core `fmt.Printf` function, but tooled to work the Cookoo way.

The following prints 'Hello' to standard out.

//...
Does(Printf, "out").
Using("format").WithDefault("%s\n")
Using("0").WithDefault("Hello")

Params:

  • format (string): The format string
  • "0"... (string): String representation of an integer ascending from 0. These are treated as positional.

func Println

func Println(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)

Println prints a string to standard output, and appends a newline.

Also see web.Flush.

Params:

  • content (string): The string to print.

func Sprintf

func Sprintf(c cookoo.Context, params *cookoo.Params) (interface{}, cookoo.Interrupt)

Sprintf formats a string and then returns the result to the context.

This is a command wrapper for the core `fmt.Sprintf` function, but tooled to work the Cookoo way.

The following returns 'Hello World' to the context.

//...
Does(Sprintf, "out").
Using("format").WithDefault("%s %s\n")
Using("0").WithDefault("Hello")
Using("1").WithDefault("World")

Params:

  • format (string): The format string
  • "0"... (string): String representation of an integer ascending from 0. These are treated as positional.

func Template

func Template(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt)

Template is a template-based text formatter.

This uses the core `text/template` to process a given string template.

Params

  • template (string): A template string.
  • template.Context (bool): If true, the context will be placed into the template renderer as 'Cxt', and can be used as `{{.Cxt.Foo}}`. False by default.
  • ... (interface{}): Values passed into the template.

Conventionally, template variables should start with an initial capital.

Returns a formatted string.

Types

This section is empty.

Jump to

Keyboard shortcuts

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