项目作者: hgfischer

项目描述 :
Conditional `fmt`
高级语言: Go
项目地址: git://github.com/hgfischer/go-bfmt.git
创建时间: 2015-03-16T00:43:30Z
项目社区:https://github.com/hgfischer/go-bfmt

开源协议:Other

下载


bfmt

Build Status

This is a package that wraps most functions present in the fmt package with a boolean conditional.

Docs can be found at http://godoc.org/github.com/hgfischer/go-bfmt

Introduction

If you ever needed to write code like this:

  1. package main
  2. import (
  3. "fmt"
  4. "flag"
  5. )
  6. var verbose bool
  7. func main() {
  8. flag.BoolVar(&verbose, "v", false, "Enable verbose output")
  9. flag.Parse()
  10. if verbose {
  11. fmt.Println("I'm chatty...")
  12. }
  13. }

Then you can now use go-bfmt to do this:

  1. package main
  2. import (
  3. "flag"
  4. "github.com/hgfischer/go-bfmt"
  5. )
  6. var verbose = bfmt.Bool(false)
  7. func main() {
  8. flag.Var(&verbose, "v", "Enable verbose output")
  9. flag.Parse()
  10. verbose.Println("I'm chatty...")
  11. }