properties

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: Apache-2.0 Imports: 5 Imported by: 1

README

properties-decoder

An optional properties decoder for goschtalt.

Build Status codecov.io Go Report Card GitHub Release GoDoc

Documentation

Overview

properties package is a goschtalt decoder package.

The properties package automatically registers the decoder as a default decoder with the goschtalt package so the usage is as simple as possible ... simply import the package and it should just work.

Import the package like you do for pprof - like this:

import (
	"fmt"
	"os"
	...

	"github.com/goschtalt/goschtalt"
	_ "github.com/goschtalt/properties-decoder"
)

See the example for how to use this extension package.

Example
// SPDX-FileCopyrightText: 2022 Weston Schmidt <weston_schmidt@alumni.purdue.edu>
// SPDX-License-Identifier: Apache-2.0
//go:build !windows

package main

import (
	"fmt"
	"strings"
	"testing/fstest"

	"github.com/goschtalt/goschtalt"
	_ "github.com/goschtalt/properties-decoder"
)

const text = `# example file
Example.Version = 1
Example.Colors.0 = red
Example.Colors.1 = green
Example.Colors.2 = blue`

func main() {
	fs := fstest.MapFS{
		"example.properties": &fstest.MapFile{
			Data: []byte(text),
			Mode: 0644,
		},
	}
	// Normally, you use something like os.DirFS("/etc/program")
	g, err := goschtalt.New(goschtalt.AddDir(fs, "."))
	if err != nil {
		panic(err)
	}

	err = g.Compile()
	if err != nil {
		panic(err)
	}

	var cfg struct {
		Example struct {
			Version int
			Colors  []string
		}
	}

	err = g.Unmarshal("", &cfg)
	if err != nil {
		panic(err)
	}

	fmt.Println("example")
	fmt.Printf("    version = %d\n", cfg.Example.Version)
	fmt.Printf("    colors  = [ %s ]\n", strings.Join(cfg.Example.Colors, ", "))

}
Output:

example
    version = 1
    colors  = [ red, green, blue ]

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decoder

type Decoder struct{}

Decoder is a class for the property decoder.

func (Decoder) Decode

func (d Decoder) Decode(ctx decoder.Context, b []byte, m *meta.Object) error

Decode decodes a byte arreay into the meta.Object tree.

func (Decoder) Extensions

func (d Decoder) Extensions() []string

Extensions returns the supported extensions.

Jump to

Keyboard shortcuts

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