headerfile

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2019 License: GPL-2.0 Imports: 4 Imported by: 1

README

GoDoc Go Report Card license Release

headerfile

This is a simple package which allows you to process files which consist of a key-value header, and then content.

Use Case

The initial-use case was for a simple blog-compiler, which consumes a series of files containing posts. As you might expect each post has some associated meta-data, such as a title, a set of tags, etc.

This library allows you to read the two parts of this file seperately, and cleanly:

Subject: This is my post
Date: 10th March 1980
Tags: foo, bar, baz

This is my blog post ..

Once parsed you can receive :

  • The body of the post.
  • A map containing the (string) keys and values present in the header.
    • The header-values may be separated by either : or =.

Github Setup

This repository is configured to run tests upon every commit, and when pull-requests are created/updated. The testing is carried out via .github/run-tests.sh which is used by the github-action-tester action.

If test-coverage drops beneath 100% this is a bug. The package is simple enough that this should not be an undue burdon.

Steve

Documentation

Overview

Package headerfile allows you to read a file which contains a small header of "key:value" lines.

These kinds of files are very common when processing simple blogs, and similar files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HeaderFile

type HeaderFile struct {

	// File is the filename the user wished us to read.
	File string
	// contains filtered or unexported fields
}

HeaderFile is the structure that encapsulates our object.

func New

func New(filename string) *HeaderFile

New creates a new object.

func (*HeaderFile) Body

func (h *HeaderFile) Body() (string, error)

Body returns the body of the file, which is the region after the header.

The body will contain an extra trailing newline.

func (*HeaderFile) Headers

func (h *HeaderFile) Headers() (map[string]string, error)

Headers returns the headers associated with the file.

The map will have all the header-names downcased, and the values will be stripped of any leading/trailing whitespace.

Jump to

Keyboard shortcuts

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