 Documentation
      ¶
      Documentation
      ¶
    
    
  
    
  
    Overview ¶
Package heredoc provides the here-document with keeping indent.
Golang supports raw-string syntax.
doc := ` Foo Bar `
But raw-string cannot recognize indent. Thus such content is indented string, equivalent to
"\n\tFoo\n\tBar\n"
I dont't want this!
However this problem is solved by package heredoc.
doc := heredoc.Doc(` Foo Bar `)
It is equivalent to
"Foo\nBar\n"
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Doc ¶
heredoc.Doc retutns unindented string as here-document.
Process of making here-document:
- Find most little indent size. (Skip empty lines)
- Remove this indents of lines.
Example (Lipsum) ¶
package main
import (
	"fmt"
	"github.com/MakeNowJust/heredoc"
)
func main() {
	fmt.Print(heredoc.Doc(`
		Lorem ipsum dolor sit amet, consectetur adipisicing elit,
		sed do eiusmod tempor incididunt ut labore et dolore magna
		aliqua. Ut enim ad minim veniam, ...
	`))
}
Output: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, ...
Example (Spec) ¶
package main
import (
	"fmt"
	"github.com/MakeNowJust/heredoc"
)
func main() {
	// Single line string is no change.
	fmt.Println(heredoc.Doc(`It is single line.`))
	// If first line is empty, heredoc.Doc removes first line.
	fmt.Println(heredoc.Doc(`
		It is first line.
		It is second line.`))
	// If last line is empty and more little length than indents,
	// heredoc.Doc removes last line's content.
	fmt.Println(heredoc.Doc(`
		Next is last line.
	`))
	fmt.Println("Previous is last line.")
}
Output: It is single line. It is first line. It is second line. Next is last line. Previous is last line.
func Docf ¶
heredoc.Docf returns unindented and formatted string as here-document. This format is same with package fmt's format.
Example ¶
package main
import (
	"fmt"
	"github.com/MakeNowJust/heredoc"
)
func main() {
	libName := "github.com/MakeNowJust/heredoc"
	author := "TSUYUSATO Kitsune (@MakeNowJust)"
	fmt.Printf(heredoc.Docf(`
		Library Name  : %s
		Author        : %s
		Repository URL: http://%s.git
	`, libName, author, libName))
}
Output: Library Name : github.com/MakeNowJust/heredoc Author : TSUYUSATO Kitsune (@MakeNowJust) Repository URL: http://github.com/MakeNowJust/heredoc.git
Types ¶
This section is empty.
 Click to show internal directories. 
   Click to hide internal directories. 
