Coder Social home page Coder Social logo

indrajithbandara / go-interpol Goto Github PK

View Code? Open in Web Editor NEW

This project forked from imkira/go-interpol

0.0 2.0 0.0 12 KB

interpol is a Go package for doing format-string like string interpolation using named parameters.

License: MIT License

Makefile 3.23% Go 96.77%

go-interpol's Introduction

interpol

License GoDoc Build Status Coverage codebeat badge goreportcard

interpol is a Go package for doing format-string like string interpolation using named parameters.

Currently, a template only accepts variable placeholders delimited by brace characters (eg. "Hello {foo} {bar}").

Install

First, you need to install the package:

go get -u github.com/imkira/go-interpol

Documentation

For advanced usage, make sure to check the available documentation here.

Example

The following code should use interpol.WithMap function, which simply replaces every key with the corresponding value of the specified map. When run, it should output Hello World!!!.

package main

import (
	"fmt"

	"github.com/imkira/go-interpol"
)

func main() {
	m := map[string]string{
		"foo": "Hello",
		"bar": "World",
	}
	str, err := interpol.WithMap("{foo} {bar}!!!", m)
	if err != nil {
		fmt.Printf("Error: %v\n", err)
		return
	}
	fmt.Println(str)
}

Contribute

Found a bug? Want to contribute and add a new feature?

Please fork this project and send me a pull request!

License

go-interpol is licensed under the MIT license:

www.opensource.org/licenses/MIT

Copyright

Copyright (c) 2016 Mario Freitas. See LICENSE for further details.

go-interpol's People

Contributors

imkira avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.