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: 3

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