namespace

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2022 License: MIT Imports: 3 Imported by: 4

README

namespace

命名空间工具,简化拼凑命名流程

很多软件如redis,自己不带命名空间.我们必须人为的构造命名空间来分隔业务.本工具就是用来做这个的.

用法

  • 构造命名空间

    namespace := NameSpcae{"a", "b", "c"}
    n := namespace.ToString(WithRedisStyle())
    //a::b::c
    k := namespace.FullName("q", WithRedisStyle())
    //a::b::c::q
    
  • 解析命名空间

    SetDefaultOptions(WithEtcdStyle())
    keyStr := "/a/b/c/d"
    namespace, key, err := FromFullName(keyStr)
    ReSetDefaultOptions()
    

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrKeyNotHaveNamespace = errors.New("key not have namespace")

ErrKeyNotHaveNamespace key没有命名空间

View Source
var ErrNamespaceFormatNotMatch = errors.New("namespace format not match")

ErrNamespaceFormatNotMatch 命名空间格式不匹配

Functions

func ReSetDefaultOptions

func ReSetDefaultOptions()

ReSetDefaultOptions 重置命名空间配置

func SetDefaultOptions

func SetDefaultOptions(opts ...optparams.Option[Options])

SetDefaultOptions 设置默认命名空间配置 @params opts ...optparams.Option[Options] 设置项

func WithEtcdStyle

func WithEtcdStyle() optparams.Option[Options]

WithEtcdStyle 设置etcd风格的命名空间设置

func WithKeyDelimiter

func WithKeyDelimiter(delimiter string) optparams.Option[Options]

WithKeyDelimiter 设置键间的分割符

func WithNamespaceDelimiter

func WithNamespaceDelimiter(delimiter string) optparams.Option[Options]

WithNamespaceDelimiter 设置命名空间间的分割符

func WithPrefix

func WithPrefix(prefix string) optparams.Option[Options]

WithPrefix 设置命名空间间的前缀

func WithRedisStyle

func WithRedisStyle() optparams.Option[Options]

WithRedisStyle 设置redis风格的命名空间设置

Types

type NameSpcae

type NameSpcae []string

NameSpcae 带命名空间的键

func FromFullName

func FromFullName(fullname string, opts ...optparams.Option[Options]) (NameSpcae, string, error)

FromFullName 从全名字符串中解析出命名空间和key @params fullname string 带解析全名 @params opts ...optparams.Option[Options] 设置项 @return NameSpcae 命名空间 @return string key @return error 解析错误

func (*NameSpcae) FullName

func (n *NameSpcae) FullName(key string, opts ...optparams.Option[Options]) string

FullName 在命名空间基础上创建一个key的全名 @params key string 用于标识的键 @params opts ...optparams.Option[Options] 设置项

func (*NameSpcae) ToString

func (n *NameSpcae) ToString(opts ...optparams.Option[Options]) string

ToString namespace转换为字符串 @params opts ...optparams.Option[Options] 设置项

type Options

type Options struct {
	Prefix             string //命名空间前缀
	NamespaceDelimiter string //各级命名空间间的分隔符
	KeyDelimiter       string //命名空间和key间的分隔符
}

Jump to

Keyboard shortcuts

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