yamlcomment

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: MIT Imports: 5 Imported by: 6 modules, 5 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

yaml-comment

golang yaml comment encoder

How to use

package main

import (
    "fmt"
    "github.com/zijiren233/yaml-comment"
)

type Config struct {
    Name string `yaml:"name,omitempty" hc:"this is head comment"`
    Age  int    `yaml:"age,omitempty" lc:"this is line comment" fc:"this is foot comment"`
}

func main() {
    c := Config{
        Name: "comment",
        Age:  18,
    }
    data, err := yamlcomment.Marshal(c)
	if err != nil {
		panic(err)
	}
    fmt.Println(string(data))
}

Output

# this is head comment
name: comment
age: 18 # this is line comment
# this is foot comment

Documentation

Index

Constants

View Source
const (
	HeadCommentTag = "hc"
	LineCommentTag = "lc"
	FootCommentTag = "fc"
	OmitemptyTag   = "omitempty"
	InlineTag      = "inline"
	FlowTag        = "flow"
)

Variables

This section is empty.

Functions

func AnyToYamlNode

func AnyToYamlNode(model any) (*yaml.Node, error)

func Marshal

func Marshal(v any) ([]byte, error)

Types

type CommentEncoder

type CommentEncoder struct {
	// contains filtered or unexported fields
}

func NewEncoder

func NewEncoder(encoder *yaml.Encoder) *CommentEncoder

func (*CommentEncoder) Encode

func (e *CommentEncoder) Encode(v any) error

Jump to

Keyboard shortcuts

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