Exemple #1
0
func (r Reference) ValueContext(ctx context.Context) (string, error) {

	env := envctx.FromContextOrNil(ctx)
	if env == nil || env.Path == "" {
		return r.Value(), nil
	}

	if r.Package == "" && r.Name == "" {
		return "", nil
	}
	if r.Package == env.Path {
		return r.Name, nil
	}
	if r.Package == "kego.io/json" {
		return fmt.Sprintf("json:%s", r.Name), nil
	}
	if r.Package == "kego.io/system" {
		return fmt.Sprintf("system:%s", r.Name), nil
	}
	for alias, pkg := range env.Aliases {
		if pkg == r.Package {
			return fmt.Sprintf("%s:%s", alias, r.Name), nil
		}
	}
	return "", kerr.New("WGCDQQCFAD", "Package %s not found in aliases", r.Package)
}
Exemple #2
0
Fichier : tests.go Projet : kego/ke
func (c *ContextBuilder) initEnv() *envctx.Env {
	env := envctx.FromContextOrNil(c.ctx)
	if env == nil {
		env = &envctx.Env{Aliases: map[string]string{}}
		c.ctx = envctx.NewContext(c.ctx, env)
	}
	return env
}