environment

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

README

环境组件(environment)

如何引用

代码配置
package main

import (
    "github.com/GuoxinL/gcomponent/environment"
)

func main() {
    environment.New()
    fmt.Println(environment.GetName())
    fmt.Println(environment.GetApplicationFile())
    fmt.Println(environment.GetProfile())
}
配置文件

配置文件夹的名称被指定为conf

  1. 单环境配置 适合可以不区分环境直接在conf文件夹下直接创建配置文件 application.yaml
-| conf
--| application.yaml
  1. 多环境配置
    conf文件夹下包含环境文件夹(用于区分不同环境),环境文件夹的名字和profile的类型一致
-| conf
--| dev
---| application.yaml
--| pro
---| application.yaml
--| test
---| application.yaml
--| uat
---| application.yaml
  1. 环境变量参数
./main --profile=dev

main 是golang二进制包 profile的类型:可以定义任何环境名称只要和配置文件的文件夹名称一致即可

Documentation

Overview

Package environment Created by guoxin in 2020/11/8 6:38 下午

Package environment Created by guoxin in 2020/4/10 11:18 上午

Index

Constants

View Source
const (
	YAML            = "yaml"
	APPLICATION     = "application"
	ConfigDirectory = "conf"

	DefaultProfile        = "dev"
	DefaultConfigFileName = APPLICATION + core.S + YAML
)

Variables

This section is empty.

Functions

func GetName

func GetName() string

GetName Get the configuration profile

func GetProfile

func GetProfile() string

GetProfile Get the configuration profile

func GetProperty

func GetProperty(prefix string, config interface{}) error

GetProperty Get the configuration in application.yaml under the current environment directory

func IsProfile

func IsProfile(profile string) bool

func IsRequestId

func IsRequestId() bool

IsRequestId Get the configuration profile

func New

func New() interface{}

Types

type Application

type Application struct {
	Name      string `mapstructure:"name"`
	Profile   string `mapstructure:"profile"`
	RequestId bool   `mapstructure:"request_id"`
}

Application The properties that Application has, If the future properties out more application-specific properties put in here

type ApplicationFile

type ApplicationFile struct {
	*viper.Viper
	// contains filtered or unexported fields
}

func GetApplicationFile

func GetApplicationFile() *ApplicationFile

GetApplicationFile Get the configuration directory application.yaml viper.Viper

func (*ApplicationFile) Directory

func (a *ApplicationFile) Directory() string

Directory Get the current configuration directory

type Configuration

type Configuration struct {
	// Make sure you only initialize it once
	core.InitializeLock
	// contains filtered or unexported fields
}

func (*Configuration) Initialize

func (c *Configuration) Initialize(params ...interface{}) interface{}

Jump to

Keyboard shortcuts

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