config

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2024 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package config provides JSON configuration

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JSON

type JSON struct {
	*encoding.JSON
}

JSON JSON format configuration file

func NewJSONFromBytes

func NewJSONFromBytes(b []byte) (*JSON, error)

NewJSONFromBytes gets json configuration from byte stream b and returns an error if the json format is wrong

func NewJSONFromEncodingJSON

func NewJSONFromEncodingJSON(j *encoding.JSON) *JSON

NewJSONFromEncodingJSON gets JSON from encoded JSON j

func NewJSONFromFile

func NewJSONFromFile(filename string) (*JSON, error)

NewJSONFromFile gets json configuration from the file named filename And return an error if there is a json format error or a file read error

func NewJSONFromString

func NewJSONFromString(s string) (*JSON, error)

NewJSONFromString gets json configuration from string s and returns an error if the json format is wrong

func (*JSON) CloneConfig

func (j *JSON) CloneConfig() *JSON

CloneConfig clones the json configuration file

func (*JSON) GetBoolOrDefaullt

func (j *JSON) GetBoolOrDefaullt(path string, defaultValue bool) bool

GetBoolOrDefaullt gets the BOOL value corresponding to the path. For the following json

{
 "a":{
    "b":[{
       c:"x"
     }]
	}
}

To access the x string, the access path for each layer of path is a, a.b, a.b.0, a.b.0.c If the corresponding path is not int64 or does not exist, defaultValue will be returned

func (*JSON) GetConfig

func (j *JSON) GetConfig(path string) (*JSON, error)

GetConfig gets the value configuration file corresponding to the path. For the following json

{
 "a":{
    "b":[{
       c:"x"
     }]
	}
}

To access the x string, the access path for each layer of path is a, a.b, a.b.0, a.b.0.c If the corresponding path is not a json structure or does not exist, an error will be returned

func (*JSON) GetConfigArray

func (j *JSON) GetConfigArray(path string) ([]*JSON, error)

GetConfigArray gets the configuration array corresponding to the path. For the following json

{
 "a":{
    "b":[{
       c:"x"
     }]
	}
}

To access the x string, the access path for each layer of path is a, a.b, a.b.0, a.b.0.c If the corresponding path is not a configuration array or does not exist, an error will be returned

func (*JSON) GetConfigMap

func (j *JSON) GetConfigMap(path string) (map[string]*JSON, error)

GetConfigMap gets the configuration mapping corresponding to the path. For the following json

{
 "a":{
    "b":[{
       c:"x"
     }]
	}
}

To access the x string, the access path for each layer of path is a, a.b, a.b.0, a.b.0.c If the corresponding path is not a configuration mapping or does not exist, an error will be returned

func (*JSON) GetFloat64OrDefaullt

func (j *JSON) GetFloat64OrDefaullt(path string, defaultValue float64) float64

GetFloat64OrDefaullt gets the float64 value corresponding to the path. For the following json

{
 "a":{
    "b":[{
       c:"x"
     }]
	}
}

To access the x string, the access path for each layer of path is a, a.b, a.b.0, a.b.0.c If the corresponding path is not float64 or does not exist, defaultValue will be returned

func (*JSON) GetInt64OrDefaullt

func (j *JSON) GetInt64OrDefaullt(path string, defaultValue int64) int64

GetInt64OrDefaullt gets the int64 value corresponding to the path. For the following json

{
 "a":{
    "b":[{
       c:"x"
     }]
	}
}

To access the x string, the access path for each layer of path is a, a.b, a.b.0, a.b.0.c If the corresponding path is not int64 or does not exist, defaultValue will be returned

func (*JSON) GetStringOrDefaullt

func (j *JSON) GetStringOrDefaullt(path string, defaultValue string) string

GetStringOrDefaullt gets the string value corresponding to the path. For the following json

{
 "a":{
    "b":[{
       c:"x"
     }]
	}
}

To access the x string, the access path for each layer of path is a, a.b, a.b.0, a.b.0.c If the corresponding path is not a string or does not exist, defaultValue will be returned

Jump to

Keyboard shortcuts

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