2017-07-05 23:10:57 +00:00
|
|
|
/*
|
|
|
|
* This file is subject to the terms and conditions defined in
|
|
|
|
* file 'LICENSE.md', which is part of this source code package.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package creator
|
|
|
|
|
|
|
|
import (
|
2017-07-13 15:35:41 +00:00
|
|
|
"errors"
|
2017-07-13 14:20:42 +00:00
|
|
|
"io"
|
2017-07-05 23:10:57 +00:00
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/unidoc/unidoc/common"
|
|
|
|
"github.com/unidoc/unidoc/pdf/model"
|
|
|
|
)
|
|
|
|
|
|
|
|
//
|
|
|
|
// The content creator is a wrapper around functionality for creating PDF reports and/or adding new
|
|
|
|
// content onto imported PDF pages.
|
|
|
|
//
|
|
|
|
type Creator struct {
|
|
|
|
pages []*model.PdfPage
|
|
|
|
activePage *model.PdfPage
|
|
|
|
|
|
|
|
pagesize PageSize
|
|
|
|
|
2017-07-06 16:26:22 +00:00
|
|
|
context DrawContext
|
2017-07-05 23:10:57 +00:00
|
|
|
|
|
|
|
pageMargins margins
|
|
|
|
|
|
|
|
pageWidth, pageHeight float64
|
|
|
|
|
|
|
|
// Keep track of number of chapters for indexing.
|
|
|
|
chapters int
|
|
|
|
|
2017-07-17 12:07:14 +00:00
|
|
|
genFrontPageFunc func(args FrontpageFunctionArgs)
|
2017-07-07 15:08:43 +00:00
|
|
|
genTableOfContentFunc func(toc *TableOfContents) (*Chapter, error)
|
2017-07-17 12:07:14 +00:00
|
|
|
drawHeaderFunc func(args HeaderFunctionArgs)
|
|
|
|
drawFooterFunc func(args FooterFunctionArgs)
|
2017-07-05 23:10:57 +00:00
|
|
|
|
|
|
|
finalized bool
|
2017-07-06 16:26:22 +00:00
|
|
|
|
|
|
|
toc *TableOfContents
|
2017-07-05 23:10:57 +00:00
|
|
|
}
|
|
|
|
|
2017-07-17 12:07:14 +00:00
|
|
|
// Input arguments to a front page drawing function.
|
|
|
|
type FrontpageFunctionArgs struct {
|
|
|
|
PageNum int
|
|
|
|
TotalPages int
|
|
|
|
}
|
|
|
|
|
|
|
|
// Input arguments to a header drawing function.
|
|
|
|
type HeaderFunctionArgs struct {
|
|
|
|
PageNum int
|
|
|
|
TotalPages int
|
|
|
|
}
|
|
|
|
|
|
|
|
// Input arguments to a footer drawing function.
|
|
|
|
type FooterFunctionArgs struct {
|
|
|
|
PageNum int
|
|
|
|
TotalPages int
|
|
|
|
}
|
|
|
|
|
|
|
|
// Margins. Can be page margins, or margins around an element.
|
2017-07-05 23:10:57 +00:00
|
|
|
type margins struct {
|
|
|
|
left float64
|
|
|
|
right float64
|
|
|
|
top float64
|
|
|
|
bottom float64
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a new instance of the PDF creator.
|
|
|
|
func New() *Creator {
|
|
|
|
c := &Creator{}
|
|
|
|
c.pages = []*model.PdfPage{}
|
|
|
|
c.SetPageSize(PageSizeLetter)
|
|
|
|
|
|
|
|
m := 0.1 * c.pageWidth
|
|
|
|
c.pageMargins.left = m
|
|
|
|
c.pageMargins.right = m
|
|
|
|
c.pageMargins.top = m
|
|
|
|
c.pageMargins.bottom = m
|
|
|
|
|
2017-07-06 16:26:22 +00:00
|
|
|
c.toc = newTableOfContents()
|
|
|
|
|
2017-07-05 23:10:57 +00:00
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
2017-07-14 13:32:22 +00:00
|
|
|
// Set the page margins: left, right, top, bottom.
|
|
|
|
// The default page margins are 10% of document width.
|
|
|
|
func (c *Creator) SetPageMargins(left, right, top, bottom float64) {
|
|
|
|
c.pageMargins.left = left
|
|
|
|
c.pageMargins.right = right
|
|
|
|
c.pageMargins.top = top
|
|
|
|
c.pageMargins.bottom = bottom
|
|
|
|
}
|
|
|
|
|
2017-07-06 16:26:22 +00:00
|
|
|
// Returns the current Page width.
|
2017-07-05 23:10:57 +00:00
|
|
|
func (c *Creator) Width() float64 {
|
|
|
|
return c.pageWidth
|
|
|
|
}
|
|
|
|
|
2017-07-06 16:26:22 +00:00
|
|
|
// Returns the current Page height.
|
2017-07-05 23:10:57 +00:00
|
|
|
func (c *Creator) Height() float64 {
|
|
|
|
return c.pageHeight
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Creator) setActivePage(p *model.PdfPage) {
|
|
|
|
c.activePage = p
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Creator) getActivePage() *model.PdfPage {
|
|
|
|
if c.activePage == nil {
|
|
|
|
if len(c.pages) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return c.pages[len(c.pages)-1]
|
|
|
|
} else {
|
|
|
|
return c.activePage
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-06 16:26:22 +00:00
|
|
|
// Set a new Page size. Pages that are added after this will be created with this Page size.
|
2017-07-05 23:10:57 +00:00
|
|
|
// Does not affect pages already created.
|
2017-07-14 13:32:22 +00:00
|
|
|
//
|
|
|
|
// Common page sizes are defined as constants.
|
|
|
|
// Examples:
|
|
|
|
// 1. c.SetPageSize(creator.PageSizeA4)
|
|
|
|
// 2. c.SetPageSize(creator.PageSizeA3)
|
|
|
|
// 3. c.SetPageSize(creator.PageSizeLegal)
|
|
|
|
// 4. c.SetPageSize(creator.PageSizeLetter)
|
|
|
|
//
|
|
|
|
// For custom sizes: Use the PPMM (points per mm) and PPI (points per inch) when defining those based on
|
|
|
|
// physical page sizes:
|
|
|
|
//
|
|
|
|
// Examples:
|
|
|
|
// 1. 10x15 sq. mm: SetPageSize(PageSize{10*creator.PPMM, 15*creator.PPMM}) where PPMM is points per mm.
|
|
|
|
// 2. 3x2 sq. inches: SetPageSize(PageSize{3*creator.PPI, 2*creator.PPI}) where PPI is points per inch.
|
|
|
|
//
|
2017-07-05 23:10:57 +00:00
|
|
|
func (c *Creator) SetPageSize(size PageSize) {
|
|
|
|
c.pagesize = size
|
|
|
|
|
2017-07-13 14:20:42 +00:00
|
|
|
c.pageWidth = size[0]
|
|
|
|
c.pageHeight = size[1]
|
2017-07-14 13:32:22 +00:00
|
|
|
|
|
|
|
// Update default margins to 10% of width.
|
|
|
|
m := 0.1 * c.pageWidth
|
|
|
|
c.pageMargins.left = m
|
|
|
|
c.pageMargins.right = m
|
|
|
|
c.pageMargins.top = m
|
|
|
|
c.pageMargins.bottom = m
|
2017-07-05 23:10:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set a function to draw a header on created output pages.
|
2017-07-17 12:07:14 +00:00
|
|
|
func (c *Creator) DrawHeader(drawHeaderFunc func(args HeaderFunctionArgs)) {
|
2017-07-05 23:10:57 +00:00
|
|
|
c.drawHeaderFunc = drawHeaderFunc
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set a function to draw a footer on created output pages.
|
2017-07-17 12:07:14 +00:00
|
|
|
func (c *Creator) DrawFooter(drawFooterFunc func(args FooterFunctionArgs)) {
|
2017-07-05 23:10:57 +00:00
|
|
|
c.drawFooterFunc = drawFooterFunc
|
|
|
|
}
|
|
|
|
|
2017-07-06 16:26:22 +00:00
|
|
|
// Set a function to generate a front Page.
|
2017-07-17 12:07:14 +00:00
|
|
|
func (c *Creator) CreateFrontPage(genFrontPageFunc func(args FrontpageFunctionArgs)) {
|
2017-07-05 23:10:57 +00:00
|
|
|
c.genFrontPageFunc = genFrontPageFunc
|
|
|
|
}
|
|
|
|
|
|
|
|
// Seta function to generate table of contents.
|
2017-07-07 15:08:43 +00:00
|
|
|
func (c *Creator) CreateTableOfContents(genTOCFunc func(toc *TableOfContents) (*Chapter, error)) {
|
2017-07-05 23:10:57 +00:00
|
|
|
c.genTableOfContentFunc = genTOCFunc
|
|
|
|
}
|
|
|
|
|
2017-07-06 16:26:22 +00:00
|
|
|
// Create a new Page with current parameters.
|
2017-07-05 23:10:57 +00:00
|
|
|
func (c *Creator) newPage() *model.PdfPage {
|
|
|
|
page := model.NewPdfPage()
|
|
|
|
|
2017-07-13 14:20:42 +00:00
|
|
|
width := c.pagesize[0]
|
|
|
|
height := c.pagesize[1]
|
2017-07-05 23:10:57 +00:00
|
|
|
|
|
|
|
bbox := model.PdfRectangle{0, 0, width, height}
|
|
|
|
page.MediaBox = &bbox
|
|
|
|
|
|
|
|
c.pageWidth = width
|
|
|
|
c.pageHeight = height
|
|
|
|
|
2017-07-06 16:26:22 +00:00
|
|
|
c.initContext()
|
|
|
|
|
|
|
|
return page
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize the drawing context, moving to upper left corner.
|
|
|
|
func (c *Creator) initContext() {
|
2017-07-05 23:10:57 +00:00
|
|
|
// Update context, move to upper left corner.
|
|
|
|
c.context.X = c.pageMargins.left
|
|
|
|
c.context.Y = c.pageMargins.top
|
|
|
|
c.context.Width = c.pageWidth - c.pageMargins.right - c.pageMargins.left
|
|
|
|
c.context.Height = c.pageHeight - c.pageMargins.bottom - c.pageMargins.top
|
2017-07-06 16:26:22 +00:00
|
|
|
c.context.PageHeight = c.pageHeight
|
|
|
|
c.context.PageWidth = c.pageWidth
|
|
|
|
c.context.Margins = c.pageMargins
|
2017-07-05 23:10:57 +00:00
|
|
|
}
|
|
|
|
|
2017-07-06 16:26:22 +00:00
|
|
|
// Adds a new Page to the creator and sets as the active Page.
|
2017-07-05 23:10:57 +00:00
|
|
|
func (c *Creator) NewPage() {
|
|
|
|
page := c.newPage()
|
|
|
|
c.pages = append(c.pages, page)
|
2017-07-14 16:37:50 +00:00
|
|
|
c.context.Page++
|
2017-07-05 23:10:57 +00:00
|
|
|
}
|
|
|
|
|
2017-07-12 15:47:22 +00:00
|
|
|
func (c *Creator) AddPage(page *model.PdfPage) error {
|
|
|
|
mbox, err := page.GetMediaBox()
|
|
|
|
if err != nil {
|
|
|
|
common.Log.Debug("Failed to get page mediabox: %v", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
c.context.X = mbox.Llx + c.pageMargins.left
|
|
|
|
c.context.Y = c.pageMargins.top
|
|
|
|
c.context.PageHeight = mbox.Ury - mbox.Lly
|
|
|
|
c.context.PageWidth = mbox.Urx - mbox.Llx
|
|
|
|
|
2017-07-05 23:10:57 +00:00
|
|
|
c.pages = append(c.pages, page)
|
2017-07-14 16:37:50 +00:00
|
|
|
c.context.Page++
|
2017-07-12 15:47:22 +00:00
|
|
|
|
|
|
|
return nil
|
2017-07-05 23:10:57 +00:00
|
|
|
}
|
|
|
|
|
2017-07-13 15:35:41 +00:00
|
|
|
// Rotate the current active page by angle degrees.
|
|
|
|
// NOTE: angleDeg must be a multiple of 90.
|
|
|
|
func (c *Creator) RotateDeg(angleDeg int64) error {
|
|
|
|
page := c.getActivePage()
|
|
|
|
if page == nil {
|
|
|
|
common.Log.Debug("Fail to rotate: no page currently active")
|
|
|
|
return errors.New("No page active")
|
|
|
|
}
|
|
|
|
if angleDeg%90 != 0 {
|
|
|
|
common.Log.Debug("Error: Page rotation angle not a multiple of 90")
|
|
|
|
return errors.New("Range check error")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do the rotation.
|
|
|
|
var rotation int64 = 0
|
|
|
|
if page.Rotate != nil {
|
|
|
|
rotation = *(page.Rotate)
|
|
|
|
}
|
|
|
|
rotation += angleDeg // Rotate by angleDeg degrees.
|
|
|
|
page.Rotate = &rotation
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-07-13 14:20:42 +00:00
|
|
|
// Get current context.
|
|
|
|
func (c *Creator) Context() DrawContext {
|
|
|
|
return c.context
|
|
|
|
}
|
|
|
|
|
2017-07-06 16:26:22 +00:00
|
|
|
// Call before writing out. Takes care of adding headers and footers, as well as generating front Page and
|
2017-07-05 23:10:57 +00:00
|
|
|
// table of contents.
|
2017-07-07 15:08:43 +00:00
|
|
|
func (c *Creator) finalize() error {
|
2017-07-05 23:10:57 +00:00
|
|
|
totPages := len(c.pages)
|
|
|
|
|
2017-07-06 16:26:22 +00:00
|
|
|
// Estimate number of additional generated pages and update TOC.
|
|
|
|
genpages := 0
|
|
|
|
if c.genFrontPageFunc != nil {
|
|
|
|
genpages++
|
|
|
|
}
|
|
|
|
if c.genTableOfContentFunc != nil {
|
|
|
|
c.initContext()
|
|
|
|
c.context.Page = genpages + 1
|
2017-07-07 15:08:43 +00:00
|
|
|
ch, err := c.genTableOfContentFunc(c.toc)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2017-07-06 16:26:22 +00:00
|
|
|
}
|
2017-07-07 15:08:43 +00:00
|
|
|
|
|
|
|
// Make an estimate of the number of pages.
|
|
|
|
blocks, _, err := ch.GeneratePageBlocks(c.context)
|
|
|
|
if err != nil {
|
|
|
|
common.Log.Debug("Failed to generate blocks: %v", err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
genpages += len(blocks)
|
|
|
|
|
|
|
|
// Update the table of content Page numbers, accounting for front Page and TOC.
|
|
|
|
for idx, _ := range c.toc.entries {
|
|
|
|
c.toc.entries[idx].PageNumber += genpages
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove the TOC chapter entry.
|
|
|
|
c.toc.entries = c.toc.entries[:len(c.toc.entries)-1]
|
2017-07-06 16:26:22 +00:00
|
|
|
}
|
|
|
|
|
2017-07-05 23:10:57 +00:00
|
|
|
hasFrontPage := false
|
2017-07-06 16:26:22 +00:00
|
|
|
// Generate the front Page.
|
2017-07-05 23:10:57 +00:00
|
|
|
if c.genFrontPageFunc != nil {
|
|
|
|
totPages++
|
|
|
|
p := c.newPage()
|
|
|
|
// Place at front.
|
|
|
|
c.pages = append([]*model.PdfPage{p}, c.pages...)
|
|
|
|
c.setActivePage(p)
|
|
|
|
|
2017-07-17 12:07:14 +00:00
|
|
|
args := FrontpageFunctionArgs{
|
|
|
|
PageNum: 1,
|
|
|
|
TotalPages: totPages,
|
|
|
|
}
|
|
|
|
c.genFrontPageFunc(args)
|
2017-07-05 23:10:57 +00:00
|
|
|
hasFrontPage = true
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.genTableOfContentFunc != nil {
|
2017-07-06 16:26:22 +00:00
|
|
|
c.initContext()
|
2017-07-07 15:08:43 +00:00
|
|
|
ch, err := c.genTableOfContentFunc(c.toc)
|
|
|
|
if err != nil {
|
|
|
|
common.Log.Debug("Error generating TOC: %v", err)
|
|
|
|
return err
|
|
|
|
}
|
2017-07-06 16:26:22 +00:00
|
|
|
ch.SetShowNumbering(false)
|
|
|
|
ch.SetIncludeInTOC(false)
|
|
|
|
|
|
|
|
blocks, _, _ := ch.GeneratePageBlocks(c.context)
|
|
|
|
tocpages := []*model.PdfPage{}
|
|
|
|
for _, block := range blocks {
|
|
|
|
block.SetPos(0, 0)
|
|
|
|
totPages++
|
|
|
|
p := c.newPage()
|
|
|
|
// Place at front.
|
|
|
|
tocpages = append(tocpages, p)
|
|
|
|
c.setActivePage(p)
|
|
|
|
c.Draw(block)
|
|
|
|
}
|
|
|
|
|
2017-07-05 23:10:57 +00:00
|
|
|
if hasFrontPage {
|
2017-07-06 16:26:22 +00:00
|
|
|
front := c.pages[0]
|
|
|
|
rest := c.pages[1:]
|
|
|
|
c.pages = append([]*model.PdfPage{front}, tocpages...)
|
|
|
|
c.pages = append(c.pages, rest...)
|
2017-07-05 23:10:57 +00:00
|
|
|
} else {
|
2017-07-06 16:26:22 +00:00
|
|
|
c.pages = append(tocpages, c.pages...)
|
2017-07-05 23:10:57 +00:00
|
|
|
}
|
2017-07-06 16:26:22 +00:00
|
|
|
|
2017-07-05 23:10:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for idx, page := range c.pages {
|
|
|
|
c.setActivePage(page)
|
|
|
|
if c.drawHeaderFunc != nil {
|
2017-07-17 12:07:14 +00:00
|
|
|
args := HeaderFunctionArgs{
|
|
|
|
PageNum: idx + 1,
|
|
|
|
TotalPages: totPages,
|
|
|
|
}
|
|
|
|
c.drawHeaderFunc(args)
|
2017-07-05 23:10:57 +00:00
|
|
|
}
|
|
|
|
if c.drawFooterFunc != nil {
|
2017-07-17 12:07:14 +00:00
|
|
|
args := FooterFunctionArgs{
|
|
|
|
PageNum: idx + 1,
|
|
|
|
TotalPages: totPages,
|
|
|
|
}
|
|
|
|
c.drawFooterFunc(args)
|
2017-07-05 23:10:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
c.finalized = true
|
2017-07-07 15:08:43 +00:00
|
|
|
|
|
|
|
return nil
|
2017-07-05 23:10:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Move absolute position to x, y.
|
|
|
|
func (c *Creator) MoveTo(x, y float64) {
|
|
|
|
c.context.X = x
|
|
|
|
c.context.Y = y
|
|
|
|
}
|
|
|
|
|
2017-07-06 16:26:22 +00:00
|
|
|
// Move draw context to absolute position x.
|
2017-07-05 23:10:57 +00:00
|
|
|
func (c *Creator) MoveX(x float64) {
|
|
|
|
c.context.X = x
|
|
|
|
}
|
|
|
|
|
2017-07-06 16:26:22 +00:00
|
|
|
// Move draw context to absolute position y.
|
2017-07-05 23:10:57 +00:00
|
|
|
func (c *Creator) MoveY(y float64) {
|
|
|
|
c.context.Y = y
|
|
|
|
}
|
|
|
|
|
2017-07-06 16:26:22 +00:00
|
|
|
// Move draw context right by relative position dx (negative goes left).
|
|
|
|
func (c *Creator) MoveRight(dx float64) {
|
2017-07-05 23:10:57 +00:00
|
|
|
c.context.X += dx
|
|
|
|
}
|
|
|
|
|
2017-07-06 16:26:22 +00:00
|
|
|
// Move draw context down by relative position dy (negative goes up).
|
|
|
|
func (c *Creator) MoveDown(dy float64) {
|
2017-07-05 23:10:57 +00:00
|
|
|
c.context.Y += dy
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw the drawable widget to the document. This can span over 1 or more pages. Additional pages are added if
|
2017-07-06 16:26:22 +00:00
|
|
|
// the contents go over the current Page.
|
2017-07-05 23:10:57 +00:00
|
|
|
func (c *Creator) Draw(d Drawable) error {
|
|
|
|
if c.getActivePage() == nil {
|
2017-07-06 16:26:22 +00:00
|
|
|
// Add a new Page if none added already.
|
2017-07-05 23:10:57 +00:00
|
|
|
c.NewPage()
|
|
|
|
}
|
|
|
|
|
|
|
|
blocks, ctx, err := d.GeneratePageBlocks(c.context)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for idx, blk := range blocks {
|
|
|
|
if idx > 0 {
|
|
|
|
c.NewPage()
|
|
|
|
}
|
|
|
|
|
|
|
|
p := c.getActivePage()
|
|
|
|
err := blk.drawToPage(p)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Inner elements can affect X, Y position and available height.
|
|
|
|
c.context.X = ctx.X
|
|
|
|
c.context.Y = ctx.Y
|
2017-07-06 16:26:22 +00:00
|
|
|
c.context.Height = ctx.PageHeight - ctx.Y - ctx.Margins.bottom
|
2017-07-05 23:10:57 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-07-13 14:20:42 +00:00
|
|
|
// Write output of creator to io.WriteSeeker interface.
|
|
|
|
func (c *Creator) Write(ws io.WriteSeeker) error {
|
2017-07-05 23:10:57 +00:00
|
|
|
if !c.finalized {
|
|
|
|
c.finalize()
|
|
|
|
}
|
2017-07-13 14:20:42 +00:00
|
|
|
|
2017-07-05 23:10:57 +00:00
|
|
|
pdfWriter := model.NewPdfWriter()
|
|
|
|
|
|
|
|
for _, page := range c.pages {
|
|
|
|
err := pdfWriter.AddPage(page)
|
|
|
|
if err != nil {
|
2017-07-06 16:26:22 +00:00
|
|
|
common.Log.Error("Failed to add Page: %s", err)
|
2017-07-05 23:10:57 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-13 14:20:42 +00:00
|
|
|
err := pdfWriter.Write(ws)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write output of creator to file.
|
|
|
|
func (c *Creator) WriteToFile(outputPath string) error {
|
2017-07-05 23:10:57 +00:00
|
|
|
fWrite, err := os.Create(outputPath)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
defer fWrite.Close()
|
|
|
|
|
2017-07-13 14:20:42 +00:00
|
|
|
err = c.Write(fWrite)
|
2017-07-05 23:10:57 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|