Documentation ¶
Overview ¶
Package lang provides constructs for defining golang language constructs and extracting information from them for documentation purposes.
Index ¶
- Variables
- type Block
- type BlockKind
- type Config
- type ConfigOption
- type Doc
- type Example
- func (ex *Example) Code() (string, error)
- func (ex *Example) Doc() *Doc
- func (ex *Example) HasOutput() bool
- func (ex *Example) Level() int
- func (ex *Example) Location() Location
- func (ex *Example) Name() string
- func (ex *Example) Output() string
- func (ex *Example) Summary() string
- func (ex *Example) Title() string
- type File
- type Func
- func (fn *Func) Doc() *Doc
- func (fn *Func) Examples() (examples []*Example)
- func (fn *Func) Level() int
- func (fn *Func) Location() Location
- func (fn *Func) Name() string
- func (fn *Func) Receiver() string
- func (fn *Func) Signature() (string, error)
- func (fn *Func) Summary() string
- func (fn *Func) Title() string
- type Location
- type Package
- func (pkg *Package) Consts() (consts []*Value)
- func (pkg *Package) Dir() string
- func (pkg *Package) Dirname() string
- func (pkg *Package) Doc() *Doc
- func (pkg *Package) Examples() (examples []*Example)
- func (pkg *Package) Funcs() (funcs []*Func)
- func (pkg *Package) Import() string
- func (pkg *Package) ImportPath() string
- func (pkg *Package) Level() int
- func (pkg *Package) Name() string
- func (pkg *Package) Summary() string
- func (pkg *Package) Types() (types []*Type)
- func (pkg *Package) Vars() (vars []*Value)
- type PackageOption
- type PackageOptions
- type Position
- type Repo
- type Type
- func (typ *Type) Consts() []*Value
- func (typ *Type) Decl() (string, error)
- func (typ *Type) Doc() *Doc
- func (typ *Type) Examples() (examples []*Example)
- func (typ *Type) Funcs() []*Func
- func (typ *Type) Level() int
- func (typ *Type) Location() Location
- func (typ *Type) Methods() []*Func
- func (typ *Type) Name() string
- func (typ *Type) Summary() string
- func (typ *Type) Title() string
- func (typ *Type) Vars() []*Value
- type Value
Constants ¶
This section is empty.
Variables ¶
var GOPRIVATE = os.Getenv("GOPRIVATE")
GOPRIVATE holds the Value of the environment variable
Functions ¶
This section is empty.
Types ¶
type Block ¶
type Block struct {
// contains filtered or unexported fields
}
Block defines a single block element (e.g. paragraph, code block) in the documentation for a symbol or package.
func NewBlock ¶
NewBlock creates a new block element of the provided kind and with the given text contents.
func (*Block) Kind ¶
Kind provides the kind of data that this block's text should be interpreted as.
type BlockKind ¶
type BlockKind string
BlockKind identifies the type of block element represented by the corresponding Block.
const ( // ParagraphBlock defines a block that represents a paragraph of text. ParagraphBlock BlockKind = "paragraph" // CodeBlock defines a block that represents a section of code. CodeBlock BlockKind = "code" // HeaderBlock defines a block that represents a section header. HeaderBlock BlockKind = "header" )
type Config ¶
type Config struct { FileSet *token.FileSet Level int Repo *Repo PkgDir string WorkDir string Log logger.Logger // contains filtered or unexported fields }
Config defines contextual information used to resolve documentation for a construct.
func NewConfig ¶
func NewConfig(log logger.Logger, workDir string, pkgDir string, opts ...ConfigOption) (*Config, error)
NewConfig generates a Config for the provided package directory. It will resolve the filepath and attempt to determine the repository containing the directory. If no repository is found, the Repo field will be set to nil. An error is returned if the provided directory is invalid.
func (*Config) DocLinkURL ¶ added in v0.5.3
DocLinkURL is a function that computes the URL for the given DocLink.
type ConfigOption ¶
ConfigOption modifies the Config generated by NewConfig.
func ConfigWithRepoOverrides ¶
func ConfigWithRepoOverrides(overrides *Repo) ConfigOption
ConfigWithRepoOverrides defines a set of manual overrides for the repository information to be used in place of automatic repository detection.
type Doc ¶
type Doc struct {
// contains filtered or unexported fields
}
Doc provides access to the documentation comment contents for a package or symbol in a structured form.
func NewDoc ¶
NewDoc initializes a Doc struct from the provided raw documentation text and with headers rendered by default at the heading level provided. Documentation is separated into block level elements using the standard rules from golang's documentation conventions.
type Example ¶
type Example struct {
// contains filtered or unexported fields
}
Example holds a single documentation example for a package or symbol.
func NewExample ¶
NewExample creates a new example from the example function's name, its documentation example and the files holding code related to the example.
func (*Example) Doc ¶
Doc provides the structured contents of the documentation comment for the example.
func (*Example) Level ¶
Level provides the default level that headers for the example should be rendered.
func (*Example) Location ¶
Location returns a representation of the node's location in a file within a repository.
func (*Example) Name ¶
Name provides a pretty-printed name for the specific example, if one was provided.
type Func ¶
type Func struct {
// contains filtered or unexported fields
}
Func holds documentation information for a single func declaration within a package or type.
func NewFunc ¶
NewFunc creates a new Func from the corresponding documentation construct from the standard library, the related token.FileSet for the package and the list of examples for the package.
func (*Func) Doc ¶
Doc provides the structured contents of the documentation comment for the function.
func (*Func) Examples ¶
Examples provides the list of examples from the list given on initialization that pertain to the function.
func (*Func) Level ¶
Level provides the default level at which headers for the func should be rendered in the final documentation.
func (*Func) Location ¶
Location returns a representation of the node's location in a file within a repository.
func (*Func) Receiver ¶
Receiver provides the type of the receiver for the function, or empty string if there is no receiver type.
func (*Func) Signature ¶
Signature provides the raw text representation of the code for the function's signature.
type Location ¶
Location holds information for identifying a position within a file and repository, if present.
type Package ¶
type Package struct {
// contains filtered or unexported fields
}
Package holds documentation information for a package and all of the symbols contained within it.
func NewPackage ¶
NewPackage creates a representation of a package's documentation from the raw documentation constructs provided by the standard library. This is only recommended for advanced scenarios. Most consumers will find it easier to use NewPackageFromBuild instead.
func NewPackageFromBuild ¶
func NewPackageFromBuild(log logger.Logger, pkg *build.Package, opts ...PackageOption) (*Package, error)
NewPackageFromBuild creates a representation of a package's documentation from the build metadata for that package. It can be configured using the provided options.
func (*Package) Dirname ¶
Dirname provides the name of the leaf directory in which the package is located.
func (*Package) Doc ¶
Doc provides the structured contents of the documentation comment for the package.
func (*Package) Examples ¶
Examples provides the package-level examples that have been defined. This does not include examples that are associated with symbols contained within the package.
func (*Package) Import ¶
Import provides the raw text for the import declaration that is used to import code from the package. If your package's documentation is generated from a local path and does not use Go Modules, this will typically print `import "."`.
func (*Package) ImportPath ¶
ImportPath provides the identifier used for the package when installing or importing the package. If your package's documentation is generated from a local path and does not use Go Modules, this will typically print `.`.
func (*Package) Level ¶
Level provides the default level that headers for the package's root documentation should be rendered.
func (*Package) Name ¶
Name provides the name of the package as it would be seen from another package importing it.
func (*Package) Summary ¶
Summary provides the one-sentence summary of the package's documentation comment.
type PackageOption ¶
type PackageOption func(opts *PackageOptions) error
PackageOption configures one or more options for the package.
func PackageWithRepositoryOverrides ¶
func PackageWithRepositoryOverrides(repo *Repo) PackageOption
PackageWithRepositoryOverrides can be used along with the NewPackageFromBuild function to define manual overrides to the automatic repository detection logic.
func PackageWithUnexportedIncluded ¶
func PackageWithUnexportedIncluded() PackageOption
PackageWithUnexportedIncluded can be used along with the NewPackageFromBuild function to specify that all symbols, including unexported ones, should be included in the documentation for the package.
type PackageOptions ¶
type PackageOptions struct {
// contains filtered or unexported fields
}
PackageOptions holds options related to the configuration of the package and its documentation on creation.
type Type ¶
type Type struct {
// contains filtered or unexported fields
}
Type holds documentation information for a type declaration.
func NewType ¶
NewType creates a Type from the raw documentation representation of the type, the token.FileSet for the package's files and the full list of examples from the containing package.
func (*Type) Decl ¶
Decl provides the raw text representation of the code for the type's declaration.
func (*Type) Examples ¶
Examples lists the examples pertaining to the type from the set provided on initialization.
func (*Type) Funcs ¶
Funcs lists the funcs related to the type. This only includes functions which return an instance of the type or its pointer.
func (*Type) Location ¶
Location returns a representation of the node's location in a file within a repository.
func (*Type) Summary ¶
Summary provides the one-sentence summary of the type's documentation comment.
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value holds documentation for a var or const declaration within a package.
func NewValue ¶
NewValue creates a new Value from the raw const or var documentation and the token.FileSet of files for the containing package.
func (*Value) Decl ¶
Decl provides the raw text representation of the code for declaring the const or var.
func (*Value) Doc ¶
Doc provides the structured contents of the documentation comment for the example.
func (*Value) Level ¶
Level provides the default level that headers for the value should be rendered.