代码拉取完成,页面将自动刷新
package gitenv
import (
"errors"
"fmt"
"os"
"path/filepath"
)
// Envcontext is
type Envcontext struct {
Env map[string]string
}
// NewEnvcontext todo
func NewEnvcontext() (*Envcontext, error) {
exe, err := os.Executable()
if err != nil {
return nil, err
}
ec := &Envcontext{Env: make(map[string]string)}
exedir := filepath.Dir(exe)
if filepath.Base(exedir) == "bin" {
ec.Env["APPDIR"] = filepath.Dir(exedir)
} else {
ec.Env["APPDIR"] = exedir
}
return ec, nil
}
// Append env
func (ec *Envcontext) Append(key, value string) error {
if len(key) == 0 || len(value) == 0 {
return errors.New("Empty key value")
}
ec.Env[key] = value
return nil
}
// Delete Env
func (ec *Envcontext) Delete(key string) error {
if _, ok := ec.Env[key]; ok {
delete(ec.Env, key)
return nil
}
return fmt.Errorf("'%s' not exists", key)
}
// Expand callback
func (ec *Envcontext) Expand(s string) string {
if _, ok := ec.Env[s]; ok {
return ec.Env[s]
}
return os.Getenv(s)
}
// Expandenv is
func (ec *Envcontext) Expandenv(s string) string {
return os.Expand(s, ec.Expand)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。