env

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: MIT Imports: 6 Imported by: 0

README

env

这是一组通用的api,为应用程序提供运行环境方面的信息

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeEnvName

func ComputeEnvName(c *Want) string

ComputeEnvName 根据条件取环境变量名称

func ComputePropertyName

func ComputePropertyName(c *Want) string

ComputePropertyName 根据条件取属性名称

func ListEnvNames

func ListEnvNames(app string) []string

ListEnvNames 列出可能的环境变量名称

func ListPropertyNames

func ListPropertyNames(app string) []string

ListPropertyNames 列出可能的属性名称

func NewMainModule

func NewMainModule() *application.ModuleBuilder

NewMainModule ...

func NewTestModule

func NewTestModule() *application.ModuleBuilder

NewTestModule ...

func SetDefaultAppName

func SetDefaultAppName(name string)

SetDefaultAppName 设置默认的应用程序名称 这个函数是一次性的,一旦设置成功,后续的调用将无效

Types

type Category

type Category string

Category ...内容分类 [data|code|config|setting|...]

const (
	CategoryData    Category = "data"
	CategoryCode    Category = "code"
	CategoryConfig  Category = "config"
	CategorySetting Category = "setting"
	CategoryHome    Category = "home"
)

定义内容分类

type Context

type Context interface {
	AppName() string

	Query(c *Want) (*Have, error)

	GetPath(c *Want) afs.Path

	GetEnvironment() environment.Table

	GetProperties() properties.Table
}

Context ...

type Have

type Have struct {
	// 条件:
	Want *Want

	// 结果:
	Value string

	// 扩展结果:
	Path afs.Path // 可选项:如果 value 是本地路径
}

Have ... 表示查询结果

type Query

type Query struct {
	Want *Want
	Have *Have

	// 这个字段用于列举支持的查询名称(可选项);
	// 如果需要查询此项,用户需要在查询时提供一个空的 map 在这里;
	Names map[string]*Want
}

Query 表示查询某个环境变量(或属性)

type Resolver added in v0.0.2

type Resolver interface {
	Resolve(q *Query, chain ResolverChain) error
}

Resolver ...

type ResolverChain added in v0.0.2

type ResolverChain interface {
	Resolve(q *Query) error
}

ResolverChain ...

type ResolverRegistration added in v0.0.2

type ResolverRegistration struct {
	Resolver Resolver
	Enabled  bool
	Priority int // 优先级越高,越靠近处理链条前端
}

ResolverRegistration ...

type ResolverRegistry added in v0.0.2

type ResolverRegistry interface {
	Registrations() []*ResolverRegistration
}

ResolverRegistry ...

type Scope

type Scope string

Scope ...作用域[application|system]

const (
	ScopeDefault Scope = ""
	ScopeApp     Scope = "application"
	ScopeSystem  Scope = "system"
)

定义作用域

type Service

type Service interface {
	ForApp(appName string) Context
}

Service ... 对外提供环境信息的服务

type User

type User string

User ...用户范围[current|share]

const (
	UserDefault User = ""
	UserCurrent User = "current"
	UserShare   User = "share"
)

定义用户范围

type Want

type Want struct {

	// 基本条件: (Env|Property) 二选一
	Env      string // 环境变量名称
	Property string // 属性名称

	// 扩展条件:
	App      string // the simple-app-name
	Category Category
	Scope    Scope
	User     User
}

Want ... 表示查询条件

Directories

Path Synopsis
gen
modules
env
src

Jump to

Keyboard shortcuts

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