pageview

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2019 License: GPL-3.0 Imports: 9 Imported by: 1

README

pageview

golang GoDoc Go Report Issues Size Tag View examples License

Purpose

Sometimes go don't want just standard web links in your web pages but a preview image showing the page you`re linking to. That is where this small package comes in. It generates – by way of calling the external wkhtmltopdf commandline utility – an image of the web page a given URL addresses. Those image files are stored locally and may be used as often as you want.

Installation

You can use Go to install this package for you:

go get github.com/mwat56/pageview

After that you can import it the usual Go way to use the library.

Usage

There are only two functions you have to worry about:

// SetCacheDirectory sets the directory to use for storing the
// generated images returning an error if `aDirectory` can't be used.
//
//	`aDirectory` The directory to store the generated images.
func SetCacheDirectory(aDirectory string) error { … }

This function must be called before any other one to make sure the generated images end up where you want them to be.

To actually create an image you'd call:

// CreateImage generates an image of `aURL` and stores it in
// `CacheDirectory` returning the file name of the saved image.
//
//	`aURL` The address of the web page to process.
func CreateImage(aURL string) (string, error) { … }

The returned string is the name of the image file. If you combine it with the directory you passed to SetCacheDirectory() you get the complete path/filename to locally access the image.

There are some more function which you will barely – if ever – need; for details refer to the source code documentation

Libraries

The great commandline utility

is required for this package to work.

Under Linux this utility is usually part of your distribution. If not, you can download wkhtmltopdf from the web and install it.

Licence

    Copyright © 2019 M.Watermann, 10247 Berlin, Germany
                    All rights reserved
                EMail : <support@mwat.de>

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

You should have received a copy of the GNU General Public License along with this program. If not, see the GNU General Public License for details.

Documentation

Overview

Package pageview implements a web page link preview.

Copyright © 2019 M.Watermann, 10247 Berlin, Germany
                All rights reserved
            EMail : <support@mwat.de>

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

You should have received a copy of the GNU General Public License along with this program. If not, see the [GNU General Public License](http://www.gnu.org/licenses/gpl.html) for details.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CacheDirectory

func CacheDirectory() string

CacheDirectory returns the directory to store the generated images.

func CreateImage

func CreateImage(aURL string) (string, error)

CreateImage generates an image of `aURL` and stores it in `CacheDirectory` returning the file name of the saved image.

`aURL` The address of the web page to process.

func MaxAge

func MaxAge() time.Duration

MaxAge returns the maximimum age of cached page images.

func PathFile

func PathFile(aURL string) string

PathFile returns the complete local path/file of `aURL`.

NOTE: This function does not check whether the file for `aURL` actually exists in the local filesystem.

func SetCacheDirectory

func SetCacheDirectory(aDirectory string) error

SetCacheDirectory sets the directory to use for storing the generated images returning an error if `aDirectory` can't be used.

`aDirectory` The directory to store the generated images.

func SetMaxAge

func SetMaxAge(aLengthInSeconds time.Duration)

SetMaxAge sets the maximimum age of cached page images.

Usually you want this property at its default value (`0`, zero) which disables an age check because you want an image of the page at the time you linked to it.

`aLengthInSeconds` is the age a page image can have before

requesting it again.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL