Skip to content

Instantly share code, notes, and snippets.

@hairyhenderson
Created May 7, 2019 01:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hairyhenderson/4555ad1571a1a33597dafb8d429b33e1 to your computer and use it in GitHub Desktop.
Save hairyhenderson/4555ad1571a1a33597dafb8d429b33e1 to your computer and use it in GitHub Desktop.
Using gomplate datasources programatically
package main
import (
"fmt"
"github.com/hairyhenderson/gomplate/data"
)
func main() {
d, err := data.NewData([]string{"ip=https://ipinfo.io"}, nil)
if err != nil {
panic(err)
}
response, err := d.Datasource("ip")
if err != nil {
panic(err)
}
m := response.(map[string]interface{})
fmt.Printf("country is %s\n", m["country"])
// country is CA
}
@rms1000watt
Copy link

Holy shit.. this is easy

@mumoshu
Copy link

mumoshu commented May 8, 2019

Awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment