lorem

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2017 License: BSD-3-Clause Imports: 9 Imported by: 0

README

Build Status Coverage Status

Generate lorem ipsum for your project.

=============

Usage

import "github.com/axiomzen/golorem"

Ranged generators

These will generate a string with a variable number of elements specified by a range you provide

// generate a word with at least min letters and at most max letters.
Word(min, max int) string  

// generate a sentence with at least min words and at most max words.
Sentence(min, max int) string

// generate a paragraph with at least min sentences and at most max sentences.
Paragraph(min, max int) string

Convenience functions

Generate some commonly occuring tidbits

Host() string
Email() string
Url() string

Struct functions

The Fill function allows you to fill a structure with lorem ipsum and other random values.

For example:

type SampleStruct struct {
	Word               string `lorem:"word"`
	WordWithRange      string `lorem:"word,10,11"`
	IgnoreMe 		   string `lorem:"-"`
}

var ss SampleStruct
lorem.Fill(&ss)

// structure is filled, do whatever now

For non strings, a random number will be used.

Maps are currently unsupported, but could easily be added.

Custom decoding is supported, but untested at the moment.

To test just fill, type go test fill_test.go fill.go lorem.go wordlist.go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Email

func Email() string

Email generates a random email (dfdf@Host())

func Fill

func Fill(spec interface{}) error

Fill will fill in the structure with random stuff using lorme ipsum for strings

func HerokuDBName

func HerokuDBName(src rand.Source) string

HerokuDBName generates a random string of lower case letters and numbers

func Host

func Host() string

Host generates a random host string (dfdfd.com) for example

func IntRange

func IntRange(min, max int) int

IntRange returns a random int between min (inclusive) and max (exclusive)

func Paragraph

func Paragraph(min, max int) string

Paragraph Generates a paragraph with a specified range of sentenences.

func ReadablePath

func ReadablePath(sentence string) string

ReadablePath converts all spaces to -, and removes . and , TODO: we should probably encode the rest?

func Sentence

func Sentence(min, max int) string

Sentence Generate a sentence with a specified range of words.

func URL

func URL() string

URL Generates a random URL

func Word

func Word(min, max int) string

Word Generates a word in a specfied range of letters.

Types

type Decoder

type Decoder interface {
	// LoremDecode will give you an example string
	// if appropriate given the tag on that field
	LoremDecode(tag, example string) error
}

Decoder is for types wanting to do their own loremizing we assume clients can do their own random numbers

type ParseError

type ParseError struct {
	Message   string
	FieldName string
	TypeName  string
	Tag       string
}

A ParseError occurs when an environment variable cannot be converted to the type required by a struct field during assignment.

func (*ParseError) Error

func (e *ParseError) Error() string

Jump to

Keyboard shortcuts

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