GithubHelp home page GithubHelp logo

gstring's Introduction

gstring Build StatusCoverageGoDoc

Python like string formatting for golang.

Why?

Golang already has great features for string formatting (entire fmt package) I missed named parameters for string formatting. Intention of this library is to mimic subset of features that python's format function offers.

Example

Simple way of formatting string is using something like this:

// outputs "some value"
gstring.Printm("{key}", map[string]interface{}{"key": "some value"})

If bracked is needed in string it can be created by escaping (two brackets). Also, single key can appear multiple times in format string:

// outpits "Bracket {, }, key value, key value, key value"
gstring.Printm("Bracket {{, }}, {key}, {key}, {key}", map[string]interaface{}{"key", "key value"})

All standard formatting options from fmt work. To specify them, add colon after key name and specify fmt package compatible formatting optinos. For example:

// outpus "3.14"
gstring.Printm("{pi:%.2f}", map[string]interface{}{"pi": math.Pi})

Installation

Run go get github.com/delicb/gstring from command line.

gstring's People

Contributors

delicb avatar maximeweyl avatar

Watchers

 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.