props

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: MIT Imports: 7 Imported by: 0

README

⚙ props

Go Doc License Coverage Test

props 是一个用于解析 properties 配置文件的库,可以应用于所有的 GoLang 应用程序中。

Read me in English

☁️ 功能特性
  • 解析 properties 配置,提供多种类型转换方式,方便配置的类型转换
🔨 安装方式
$ go get -u github.com/FishGoddess/props
💡 参考案例
package main

import (
	"fmt"

	"github.com/FishGoddess/props"
)

func main() {
	// Load properties from a file.
	properties, err := props.LoadFile("load.properties")
	if err != nil {
		panic(err)
	}

	// Get one key from properties and covert it into a integer.
	fmt.Println(properties.Get("key1"))
	fmt.Println(properties.Get("key1").Int())

	// List all entries in properties.
	// Returns false if you want to continue listing.
	properties.List(func(key string, value props.Value) (finished bool) {
		fmt.Println(key, value)
		return false
	})

	// Use StoreFile to store a props to a file.
	// What's more, we provide StoreMap and StoreWriter to store a props to map and writer.
	err = props.StoreFile(properties, "store.properties")
	if err != nil {
		panic(err)
	}
}
👀 贡献者

如果您觉得 props 缺少您需要的功能,请不要犹豫,马上参与进来,发起一个 issue

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	FilePerm fs.FileMode = 0644
)

Functions

func StoreFile added in v0.3.0

func StoreFile(props *Props, file string) error

func StoreMap added in v0.3.0

func StoreMap(props *Props) map[string]Value

func StoreWriter added in v0.3.0

func StoreWriter(props *Props, writer io.Writer) error

Types

type Props added in v0.3.0

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

func LoadFile added in v0.3.0

func LoadFile(file string) (*Props, error)

func LoadMap added in v0.3.0

func LoadMap(entries map[string]Value) *Props

func LoadReader added in v0.3.0

func LoadReader(reader io.Reader) (*Props, error)

func New added in v0.3.0

func New() *Props

func (*Props) Count added in v0.3.0

func (p *Props) Count() int

func (*Props) Delete added in v0.3.0

func (p *Props) Delete(key string)

func (*Props) Get added in v0.3.0

func (p *Props) Get(key string) Value

func (*Props) List added in v0.3.0

func (p *Props) List(f func(key string, value Value) (finished bool))

func (*Props) Set added in v0.3.0

func (p *Props) Set(key string, value Value)

type Value added in v0.2.0

type Value string

func (Value) Float32 added in v0.2.0

func (v Value) Float32() (float32, error)

func (Value) Float64 added in v0.2.0

func (v Value) Float64() (float64, error)

func (Value) Int added in v0.2.0

func (v Value) Int() (int, error)

func (Value) Int16 added in v0.2.0

func (v Value) Int16() (int16, error)

func (Value) Int32 added in v0.2.0

func (v Value) Int32() (int32, error)

func (Value) Int64 added in v0.2.0

func (v Value) Int64() (int64, error)

func (Value) Int8 added in v0.2.0

func (v Value) Int8() (int8, error)

func (Value) String added in v0.2.0

func (v Value) String() string

func (Value) Uint added in v0.2.0

func (v Value) Uint() (uint, error)

func (Value) Uint16 added in v0.2.0

func (v Value) Uint16() (uint16, error)

func (Value) Uint32 added in v0.2.0

func (v Value) Uint32() (uint32, error)

func (Value) Uint64 added in v0.2.0

func (v Value) Uint64() (uint64, error)

func (Value) Uint8 added in v0.2.0

func (v Value) Uint8() (uint8, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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