8000 GitHub - liderman/text-generator: Golang text generator for generate SEO texts
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

liderman/text-generator

Repository files navigation

text-generator

Fast text generator on a mask.

Go Report Card codecov Go Reference Release

Written in Golang. I do not use regular expressions and the fastest. I covered tests and simple! Supporting recursive text generation rules.

Installation

go get github.com/liderman/text-generator

Usage

An example of a simple template text generation:

tg := textgenerator.New()
template := "Good {morning|day}!"

fmt.Print(tg.Generate(template))
// Displays: Good morning!

fmt.Print(tg.Generate(template))
// Displays: Good day!

An example of a complex generation template text:

tg := textgenerator.New()
template := "{Good {morning|evening|day}|Goodnight|Hello}, {friend|brother}! {How are you|What's new with you}?"

fmt.Print(tg.Generate(template))
// Displays: Good morning, friend! How are you?

fmt.Print(tg.Generate(template))
// Displays: Good day, brother! What's new with you?

fmt.Print(tg.Generate(template))
// Displays: Hello, friend! How are you?
...

Requirements

  • Need at least go1.14 or newer.
  • Features

    • Without external dependencies
    • Fast (does not use regular expressions)
    • Simple
    • Supports caching
    • Covered with tests

    Documentation

    You can read package documentation here.

    Testing

    Unit-tests:

    go test -v -race ./...

    Run linter:

    docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.40 golangci-lint run -v

    Benchmarks

    go test -test.bench . -benchmem -benchtime=10s

    The test result on computer MacBook Pro 2020 (Intel Core i5):

    goos: darwin
    goarch: amd64
    pkg: github.com/liderman/text-generator
    BenchmarkGenerateEasyText-8             22446540               531 ns/op             200 B/op          8 allocs/op
    BenchmarkGenerateComplexText-8           4721838              2552 ns/op            1351 B/op         24 allocs/op
    PASS
    ok      github.com/liderman/text-generator      27.227s
    

    CONTRIBUTE

    • write code
    • run go fmt ./...
    • run all linters and tests (see above)
    • create a PR describing the changes

    LICENSE

    MIT

    AUTHOR

    Konstantin Osipov k.osipov.msk@gmail.com

Packages

No packages published

Languages

0