yamldoc-go

module
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2023 License: MIT

README

yamldoc-go

A standalone version of the YAML Code Documentation approach described at https://www.talos-systems.com/blog/documentation-as-code/. All credits goes to original authors.

Changes
  • Added support for example name based comments
  • Fixed a panic with embedded structs and added support for them.
  • Complete rewrite of docgen using dst to support multi-package structure organization.
Usage

The general recommendation is, all the structures for a single type should be in a single file.

The following go:generate command will generate docs for a specified file.

//go:generate dstdocgen -path ~/khulnasoft-labs/nuclei/v2/pkg/templates -structure Template -output output.go
$ go generate pkg/<path_to_file>.go

Below is an example struct with all supported annotation as examples.

kubeletExtraMountsExample = []specs.Mount{
		{
			Source:      "/var/lib/example",
			Destination: "/var/lib/example",
			Type:        "bind",
			Options: []string{
				"rshared",
				"rw",
			},
		},
	}

...

type Config struct {
    // description: |
    //   Indicates the schema used to decode the contents.
    // values:
    //   - v1alpha1
    ConfigVersion string `yaml:"version"`
    // description: |
    //   Enable verbose logging.
    // values:
    //   - true
    //   - yes
    //   - false
    //   - no
    ConfigDebug bool `yaml:"debug"`
    //   description: |
    //     The `image` field is an optional reference to an alternative kubelet image.
    //   examples:
    //     - value: '"docker.io/<org>/kubelet:latest"'
    KubeletImage string `yaml:"image,omitempty"`
    //   description: |
    //     The `extraArgs` field is used to provide additional flags to the kubelet.
    //   examples:
    //     - name: Description for this example
    //       value: >
    //         map[string]string{
    //           "key": "value",
    //         }
    KubeletExtraArgs map[string]string `yaml:"extraArgs,omitempty"`
    //   description: |
    //     The `extraMounts` field is used to add additional mounts to the kubelet container.
    //   examples:
    //     - value: kubeletExtraMountsExample
    KubeletExtraMounts []specs.Mount `yaml:"extraMounts,omitempty"`
}

Directories

Path Synopsis
cmd
docgen
This Source Code Form is subject to the terms of the Mozilla Public License, v.
This Source Code Form is subject to the terms of the Mozilla Public License, v.
go:generate docgen types.go types_doc.go Configuration
go:generate docgen types.go types_doc.go Configuration

Jump to

Keyboard shortcuts

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