stringFormatter

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2021 License: Apache-2.0 Imports: 4 Imported by: 30

README

This is a tiny GO module for template text formatting like in C# or/and Python

## Examples

#### Format by arg order
i.e. you have following template:  Hello {0}, we are greeting you here: {1}!

if you call Format with args "manager" and "salesApp" : Format("Hello {0}, we are greeting you here: {1}!", "manager", "salesApp")

you get string "Hello manager, we are greeting you here: salesApp!"

#### Format by arg key
i.e. you have following template: "Hello {user} what are you doing here {app} ?"

if you call FormatComplex with args "vpupkin" and "mn_console" FormatComplex("Hello {user} what are you doing here {app} ?", map[string]interface{}{"user":"vpupkin", "app":"mn_console"})

you get string "Hello vpupkin what are you doing here mn_console ?"

another example is: 

```go
    strFormatResult = FormatComplex("Current app settings are: ipAddr: {ipaddr}, port: {port}, use ssl: {ssl}.", map[string]interface{}{"ipaddr":"127.0.0.1", "port":5432, "ssl":false})
```
a result will be: "Current app settings are: ipAddr: 127.0.0.1, port: 5432, use ssl: false."

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Format

func Format(template string, args ...interface{}) string

Func that makes string formatting from template * It differs from above function only by generic interface that allow to use only primitive data types: * - integers (int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uin64) * - floats (float32, float64) * - boolean * - string * - complex

func FormatComplex

func FormatComplex(template string, args map[string]interface{}) string

Func that format more complex templates like "Hello {username} here is our application {appname} *

Types

This section is empty.

Jump to

Keyboard shortcuts

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