envar

package
v0.0.86 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2021 License: MIT Imports: 6 Imported by: 0

README

ENVAR

компонент предназначен для чтения env (настроек окружения)

Пример использования

package main

import (
	"fmt"
	"log"

	"github.com/nobuenhombre/suikat/pkg/envar"
)

type AppConfig struct {
	Path           string  `env:"PATH:string=/some/default/path"`
	Port           int     `env:"PORT:int=8080"`
	Coefficient    float64 `env:"COEFFICIENT:float64=75.31"`
	MakeSomeAction bool    `env:"MSA:bool=false"`
}

func (cfg *AppConfig) Load() error {
	return envar.Load(cfg)
}

func main() {
	cfg := &AppConfig{}

	err := cfg.Load()
	if err != nil {
		log.Fatalf("ENV config error [%v]", err)
	}

	fmt.Printf("%#v", cfg)
}

Documentation

Index

Constants

View Source
const (
	TagEnvExample      = "NAME:valueType=defaultValue"
	CountPartsTagData  = 2
	CountPartsNameType = 2
)

Variables

This section is empty.

Functions

func Load added in v0.0.14

func Load(structData interface{}) error

func NewTagProcessor added in v0.0.14

func NewTagProcessor() refavour.TagProcessor

Types

type EnvVar

type EnvVar struct {
	Key          string
	DefaultValue interface{}
}

func (*EnvVar) GetBool

func (ev *EnvVar) GetBool() bool

func (*EnvVar) GetFloat64 added in v0.0.14

func (ev *EnvVar) GetFloat64() float64

func (*EnvVar) GetInt

func (ev *EnvVar) GetInt() int

func (*EnvVar) GetString

func (ev *EnvVar) GetString() string

type FieldInfo added in v0.0.47

type FieldInfo struct {
	Type         reflect.Type
	Name         string
	ValueType    string
	DefaultValue string
}

type TagInfo added in v0.0.47

type TagInfo struct {
	Tag string
}

func (*TagInfo) GetFieldInfo added in v0.0.47

func (tag *TagInfo) GetFieldInfo(typeField reflect.StructField, valueField reflect.Value) (interface{}, error)

type UnknownValueTypeError added in v0.0.14

type UnknownValueTypeError struct {
	ValueType string
}

Ошибка - Неизвестный тип значения --------------------------------------------------

func (*UnknownValueTypeError) Error added in v0.0.14

func (e *UnknownValueTypeError) Error() string

Jump to

Keyboard shortcuts

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