Categorygithub.com/Golang-Tools/namespace
modulepackage
0.0.2
Repository: https://github.com/golang-tools/namespace.git
Documentation: pkg.go.dev

# 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()
    

# Functions

FromFullName 从全名字符串中解析出命名空间和key@params fullname string 带解析全名@params opts ...optparams.Option[Options] 设置项@return NameSpcae 命名空间@return string key@return error 解析错误.
ReSetDefaultOptions 重置命名空间配置.
SetDefaultOptions 设置默认命名空间配置@params opts ...optparams.Option[Options] 设置项.
WithEtcdStyle 设置etcd风格的命名空间设置.
WithKeyDelimiter 设置键间的分割符.
WithNamespaceDelimiter 设置命名空间间的分割符.
WithPrefix 设置命名空间间的前缀.
WithRandomKeyGen 指定随机生成key时使用的随机算法.
WithRedisStyle 设置redis风格的命名空间设置.

# Variables

ErrKeyNotHaveNamespace key没有命名空间.
ErrNamespaceFormatNotMatch 命名空间格式不匹配.

# Structs

No description provided by the author

# Type aliases

NameSpcae 带命名空间的键.