2020-07-22 14:50:08 +00:00
|
|
|
// Copyright 2014 beego Author. All Rights Reserved.
|
|
|
|
// Copyright 2017 Faissal Elamraoui. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
// Package env is used to parse environment.
|
|
|
|
package env
|
|
|
|
|
|
|
|
import (
|
2020-12-12 13:28:58 +00:00
|
|
|
"github.com/astaxie/beego/core/config/env"
|
2020-07-22 14:50:08 +00:00
|
|
|
)
|
|
|
|
|
2020-11-26 09:48:29 +00:00
|
|
|
// Get returns a value by key.
|
2020-07-22 14:50:08 +00:00
|
|
|
// If the key does not exist, the default value will be returned.
|
|
|
|
func Get(key string, defVal string) string {
|
2020-12-12 13:28:58 +00:00
|
|
|
return env.Get(key, defVal)
|
2020-07-22 14:50:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MustGet returns a value by key.
|
|
|
|
// If the key does not exist, it will return an error.
|
|
|
|
func MustGet(key string) (string, error) {
|
2020-12-12 13:28:58 +00:00
|
|
|
return env.MustGet(key)
|
2020-07-22 14:50:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set sets a value in the ENV copy.
|
|
|
|
// This does not affect the child process environment.
|
|
|
|
func Set(key string, value string) {
|
|
|
|
env.Set(key, value)
|
|
|
|
}
|
|
|
|
|
|
|
|
// MustSet sets a value in the ENV copy and the child process environment.
|
|
|
|
// It returns an error in case the set operation failed.
|
|
|
|
func MustSet(key string, value string) error {
|
2020-12-12 13:28:58 +00:00
|
|
|
return env.MustSet(key, value)
|
2020-07-22 14:50:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetAll returns all keys/values in the current child process environment.
|
|
|
|
func GetAll() map[string]string {
|
2020-12-12 13:28:58 +00:00
|
|
|
return env.GetAll()
|
2020-07-22 14:50:08 +00:00
|
|
|
}
|