source

package
v0.0.0-...-73295e5 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2017 License: GPL-3.0 Imports: 11 Imported by: 4

README

Codeform sources

Sources are how Codeform reads the Go code (and templates) in order to generate output.

A source is a string that contains a reference to a valid local or online source.

Valid sources

A source may be:

  1. A local path to a file
  2. A local path to a package (directory)
  3. A go get style path to a package (e.g. github.com/matryer/codeform)
  4. A go get style path to a nested package (e.g. github.com/matryer/codeform/render/testdata/types)
  5. A go get style path to a file (e.g. github.com/matryer/codeform/render/testdata/types/interfaces.go)
  6. A URL to a file (e.g. https://raw.githubusercontent.com/matryer/codeform/master/render/testdata/types/interfaces.go)
  7. "default" string indicating the default/source.go file
  8. template:{path} template from the github.com/matryer/codeform-templates repository

Documentation

Overview

Package source provides a way to refer to source files. Valid sources include:

/local/path/to/file.go
/local/path/to/package
github.com/matryer/package
github.com/matryer/package/specific-file.go
https://domain.com/path/to/file

Index

Constants

This section is empty.

Variables

View Source
var DefaultLookup = &Lookup{}

DefaultLookup is a default Lookup instance.

Functions

This section is empty.

Types

type ErrNotFound

type ErrNotFound string

ErrNotFound indicates the source file could not be found.

func (ErrNotFound) Error

func (e ErrNotFound) Error() string

type Lookup

type Lookup struct {
	Client http.Client
}

Lookup provides source lookup capabilities.

func (*Lookup) Get

func (l *Lookup) Get(src string) (*Source, error)

Get gets the file at the given source. Valid sources include local paths, URLs, or go gettable paths. Sources must be closed. Valid sources include:

/local/path/to/file.go
/local/path/to/package
github.com/matryer/package
github.com/matryer/package/specific-file.go
https://domain.com/path/to/file

Special strings

The string "default" will be taken to mean the default source file which can be found in default/source.go. A special template prefix will indicate the template is hosted in the official https://github.com/matryer/codeform-templates repository.

template:testing/mocking/mock

type Source

type Source struct {
	Path  string
	IsDir bool
	// contains filtered or unexported fields
}

Source represents the source of a code file or package. Sources must always be closed.

func MustLocal

func MustLocal(src string) *Source

MustLocal gets a local source. Panics if the local source is invalid.

func Reader

func Reader(path string, r io.Reader) *Source

Reader gets a Source for the specified io.Reader.

func (*Source) Close

func (s *Source) Close() error

Close closes the Source and cleans up any used resources.

func (*Source) Read

func (s *Source) Read(b []byte) (int, error)

Read implements io.Reader and is a safe way of reading files.

Directories

Path Synopsis
Package defaultsource provides a staple source from which templates may be written.
Package defaultsource provides a staple source from which templates may be written.

Jump to

Keyboard shortcuts

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