github.com/enetx/g@v1.0.80/examples/format.go (about)

     1  package main
     2  
     3  import (
     4  	"github.com/enetx/g"
     5  )
     6  
     7  func main() {
     8  	foo := g.String("foo")
     9  	bar := "bar"
    10  
    11  	g.Format(g.String("foo: {foo}, bar: {bar}"), map[string]any{"foo": foo, "bar": bar}).Print()
    12  	g.Format("foo: {foo}, bar: {bar}", map[g.String]any{"foo": foo, "bar": bar}).Print()
    13  	g.Format("foo: {foo}, bar: {bar}", g.Map[string, any]{"foo": foo, "bar": bar}).Print()
    14  	g.Format("foo: {foo}, bar: {bar}", g.Map[g.String, any]{"foo": foo, "bar": bar}).Print()
    15  
    16  	name := "John"
    17  	age := 30
    18  	city := "New York"
    19  
    20  	named := map[string]any{
    21  		"name": name,
    22  		"age":  age,
    23  		"city": city,
    24  	}
    25  
    26  	f := g.Format("Hello, my name is {name}. I am {age} years old and live in {city}.", named)
    27  	f.Print()
    28  }