本文整理汇总了Golang中encoding/base32.NewEncoding函数的典型用法代码### 示例。如果您正苦于以下问题:Golang NewEncoding函数的具体用法?Golang NewEncoding怎么用?Golang NewEncoding使用的例子?那么恭喜您, 这里精选的函数代码### 示例或许可以为您提供帮助。

在下文中一共展示了NewEncoding函数的10个代码### 示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码### 示例。

示例1: ExampleNewEncoding1

func ExampleNewEncoding1() {

    enc := base32.NewEncoding(encodeTest)

    src := "this is a test string."
    dst := enc.EncodeToString([]byte(src))

    // 最后不足8字节的会用"="补全
    fmt.Println(dst)
    fmt.Println(len(dst)%8 == 0)

    // Output:
    // ------------------------------------====
    // true

}

开发者ID:JamesJiangCHN,项目名称:gopkg,代码行数:16,代码来源:NewEncoding_test.go

示例2: main

func main() {
    flag.Parse()
    b, err := ioutil.ReadAll(os.Stdin)
    if err != nil {
        fmt.Fprintf(os.Stderr, "%s\n", err)
        os.Exit(1)
    }
    alpha := *fAlphabet
    enc, ok := encodings[alpha]
    if !ok {
        if len(alpha) != 32 {
            fmt.Fprintf(os.Stderr, "unknown alphabet: %s\n", alpha)
            os.Exit(2)
        }
        enc = base32.NewEncoding(alpha)
    }
    s := enc.EncodeToString(b)
    if *fLowerCase {
        s = strings.ToLower(s)
    }
    if *fTrimPadding {
        s = strings.TrimRight(s, "=")
    }
    g := *fGroup
    if g > 0 {
        rs := ""
        for i, r := range s {
            if i > 0 && i%g == 0 {
                rs += *fGroupSep
            }
            rs += string(r)
        }
        s = rs
    }
    fmt.Println(s)
}

开发者ID:dchest,项目名称:base32util,代码行数:36,代码来源:main.go

示例3: NewLocAppError

    }
}

func NewLocAppError(where string, id string, params map[string]interface{}, details string) *AppError {
    ap := &AppError{}
    ap.Id = id
    ap.params = params
    ap.Message = id
    ap.Where = where
    ap.DetailedError = details
    ap.StatusCode = 500
    ap.IsOAuth = false
    return ap
}

var encoding = base32.NewEncoding("ybndrfg8ejkmcpqxot1uwisza345h769")

// NewId is a globally unique identifier.  It is a [A-Z0-9] string 26
// characters long.  It is a UUID version 4 Guid that is zbased32 encoded
// with the padding stripped off.
func NewId() string {
    var b bytes.Buffer
    encoder := base32.NewEncoder(encoding, &b)
    encoder.Write(uuid.NewRandom())
    encoder.Close()
    b.Truncate(26) // removes the '==' padding
    return b.String()
}

func NewRandomString(length int) string {
    var b bytes.Buffer

开发者ID:ChrisOHu,项目名称:platform,代码行数:31,代码来源:utils.go

示例4: Base32Decode

)

// RFC 4648 without padding

const base32EncodeHexLower = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"

const padding_rune = '='
const padding_1 = "="
const padding_2 = "=="
const padding_3 = "==="
const padding_4 = "===="
const padding_5 = "====="
const padding_6 = "======"
const padding_7 = "======="

var base32EncodeHexLowerInstance = base32.NewEncoding(base32EncodeHexLower)

func Base32Decode(str string) ([]byte, error) {
    length := len(str)
    remainder := length % 8
    if remainder != 0 {
        missing := 8 - remainder
        newString := make([]byte, length+missing)
        copy(newString, str)
        copy(newString[length:], padding(missing))
        return base32EncodeHexLowerInstance.DecodeString(string(newString))
    } else {
        return base32EncodeHexLowerInstance.DecodeString(str)
    }
}

开发者ID:cronosun,项目名称:buranv1,代码行数:30,代码来源:base32.go

示例5: idToName

    // API version of the oidc resources. For example "oidc.coreos.com". This is
    // currently not configurable, but could be in the future.
    apiVersion string

    // This is called once the client's Close method is called to signal goroutines,
    // such as the one creating third party resources, to stop.
    cancel context.CancelFunc
}

// idToName maps an arbitrary ID, such as an email or client ID to a Kubernetes object name.
func (c *client) idToName(s string) string {
    return idToName(s, c.hash)
}

// Kubernetes names must match the regexp '[a-z0-9]([-a-z0-9]*[a-z0-9])?'.
var encoding = base32.NewEncoding("abcdefghijklmnopqrstuvwxyz234567")

func idToName(s string, h func() hash.Hash) string {
    return strings.TrimRight(encoding.EncodeToString(h().Sum([]byte(s))), "=")
}

func (c *client) urlFor(apiVersion, namespace, resource, name string) string {
    basePath := "apis/"
    if apiVersion == "v1" {
        basePath = "api/"
    }

    var p string
    if namespace != "" {
        p = path.Join(basePath, apiVersion, "namespaces", namespace, resource, name)
    } else {

开发者ID:ericchiang,项目名称:dex,代码行数:31,代码来源:client.go

最后编辑: kuteng  文档更新时间: 2021-08-23 19:14   作者:kuteng