Documentation
¶
Overview ¶
Simple Example
package main
import (
"fmt"
"github.com/choueric/jconfig"
)
const DefContent = `{
"server": "127.0.0.1:8088"
}
`
type Config struct {
Server string `json:"server"`
}
func getConfig() *Config {
// NOTE: Config{} is the your own type to store configurations.
jc := jconfig.New("config.json", Config{})
if _, err := jc.Load(DefContent); err != nil {
fmt.Println("load config error:", err)
return nil
}
return jc.Data().(*Config) // convert to your own type and return.
}
Package jconfig provides struct JConfig to handle with configurations in JSON format.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type JConfig ¶
type JConfig struct {
// contains filtered or unexported fields
}
JConfig structure is an entity representing configurations.
func New ¶
New returns a pointer of JConfig that contains information of configuration file path and variable i of user-defined configuration type.
func (*JConfig) Data ¶
func (c *JConfig) Data() interface{}
Data retruns the user-defined configuration data.
Click to show internal directories.
Click to hide internal directories.