Documentation
¶
Index ¶
- Constants
- Variables
- type Config
- type EnvVar
- type Viewer
- func (v *Viewer) ConfigHandler(rw http.ResponseWriter, r *http.Request)
- func (v *Viewer) DetailedConfigHandler(rw http.ResponseWriter, r *http.Request)
- func (v *Viewer) EnvNotation(jsonField string) EnvVar
- func (v *Viewer) Envs() []*EnvVar
- func (v *Viewer) EnvsHandler(rw http.ResponseWriter, r *http.Request)
- func (v *Viewer) JSONNotation(envVarNotation string) EnvVar
- func (v *Viewer) ParseEnvs() []string
Constants ¶
const ( // JSONQueryKey is the query key for JSONHandler JSONQueryKey = "field" // EnvQueryKey is the query key for EnvsHandler EnvQueryKey = "env" )
const StructViewerTag = "structviewer"
Variables ¶
var ( // ErrNilConfig is returned when the Config struct is nil. ErrNilConfig = errors.New("invalid Config structure provided") // ErrEmptyStruct is returned when config.Object is nil ErrEmptyStruct = errors.New("empty Struct in configuration") // ErrInvalidObjectType is returned when config.Object is not a struct. ErrInvalidObjectType = errors.New("invalid object type") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Object represents the config struct that is going to be parsed.
Object interface{}
// ParseComments decides parsing comments of given Object or not. If it is set to false,
// the comment parser skips parsing comments of given Object.
ParseComments bool
// Path is the file path of the Object. Needed for comment parser.
// Default value is "./config.go".
Path string
}
Config represents configuration structure.
type EnvVar ¶
type EnvVar struct {
// ConfigField represents a JSON notation of the given struct fields.
ConfigField string `json:"config_field,omitempty"`
// Env represents an environment variable notation of the given struct fields.
Env string `json:"env,omitempty"`
// Description represents the comment of the given struct fields.
Description string `json:"description,omitempty"`
// Value represents the value of the given struct fields.
Value interface{} `json:"value"`
// Obfuscated represents whether the given struct field is obfuscated or not.
// This is a pointer to a boolean value to distinguish between the zero value
// and the actual value (because of the 'omitempty' tag).
Obfuscated *bool `json:"obfuscated,omitempty"`
// contains filtered or unexported fields
}
EnvVar is a key:value string struct for environment variables representation
type Viewer ¶
type Viewer struct {
// contains filtered or unexported fields
}
Viewer is the pkg control structure where the prefix and env vars are stored.
func New ¶
New receives a configuration structure and a prefix and returns a Viewer struct to manipulate this library.
func (*Viewer) ConfigHandler ¶
func (v *Viewer) ConfigHandler(rw http.ResponseWriter, r *http.Request)
ConfigHandler exposes the configuration struct as JSON fields
func (*Viewer) DetailedConfigHandler ¶
func (v *Viewer) DetailedConfigHandler(rw http.ResponseWriter, r *http.Request)
DetailedConfigHandler exposes the detailed configuration struct as JSON fields
func (*Viewer) EnvNotation ¶
EnvNotation takes JSON notation of a configuration field (e.g, 'listen_port') and returns EnvVar object of the given notation.
func (*Viewer) EnvsHandler ¶
func (v *Viewer) EnvsHandler(rw http.ResponseWriter, r *http.Request)
EnvsHandler expose the environment variables of the configuration struct
func (*Viewer) JSONNotation ¶
JSONNotation takes environment variable and returns EnvVars object of the given environment variable.