本文整理汇总了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
示例6: encode
// Copyright 2016 Attic Labs, Inc. All rights reserved.
// Licensed under the Apache License, version 2.0:
// http://www.apache.org/licenses/LICENSE-2.0
package hash
import "encoding/base32"
var encoding = base32.NewEncoding("0123456789abcdefghijklmnopqrstuv")
func encode(data []byte) string {
return encoding.EncodeToString(data)
}
func decode(s string) []byte {
slice, _ := encoding.DecodeString(s)
return slice
}
开发者ID:Richardphp,项目名称:noms,代码行数:18,代码来源:base32.go
示例7: simpleSubdomainSafeHash
pod.Name = simpleSubdomainSafeHash(filename)
if len(pod.UID) == 0 {
pod.UID = simpleSubdomainSafeHash(filename)
}
if len(pod.Namespace) == 0 {
pod.Namespace = api.NamespaceDefault
}
if glog.V(4) {
glog.Infof("Got pod from file %q: %#v", filename, pod)
} else {
glog.V(1).Infof("Got pod from file %q: %s.%s (%s)", filename, pod.Namespace, pod.Name, pod.UID)
}
return pod, nil
}
var simpleSubdomainSafeEncoding = base32.NewEncoding("0123456789abcdefghijklmnopqrstuv")
var unsafeDNSLabelReplacement = regexp.MustCompile("[^a-z0-9]+")
// simpleSubdomainSafeHash generates a pod name for the given path that is
// suitable as a subdomain label.
func simpleSubdomainSafeHash(path string) string {
name := strings.ToLower(filepath.Base(path))
name = unsafeDNSLabelReplacement.ReplaceAllString(name, "")
hasher := sha1.New()
hasher.Write([]byte(path))
sha := simpleSubdomainSafeEncoding.EncodeToString(hasher.Sum(nil))
return fmt.Sprintf("%.15s%.30s", name, sha)
}
开发者ID:ericcapricorn,项目名称:kubernetes,代码行数:29,代码来源:file.go
示例8: constructMAC
type WriteCloser struct {
io.Writer
io.Closer
}
func constructMAC(message, key []byte) []byte {
mac := hmac.New(sha256.New, key)
mac.Write(message)
return mac.Sum(nil)
}
func checkMAC(message, messageMAC, key []byte) bool {
return hmac.Equal(messageMAC, constructMAC(message, key))
}
var base32Encoder = base32.NewEncoding("abcdefghjkmnopqrstuvwxyz23456789")
func generateRandomBytes(nbytes int) ([]byte, error) {
uuid := make([]byte, nbytes)
n, err := rand.Read(uuid)
if n != len(uuid) || err != nil {
return []byte{}, err
}
return uuid, nil
}
func generateRandomBase32String(nbytes, outlen int) (string, error) {
uuid, err := generateRandomBytes(nbytes)
if err != nil {
return "", err
开发者ID:Saectar,项目名称:ghostbin,代码行数:31,代码来源:util.go
示例9: EncodeToString
package encoding
import (
"encoding/base32"
"encoding/base64"
)
const i2pB64alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-~"
// Base64I2P is base64 encoding that is used for destination keys in i2p
var Base64I2P = base64.NewEncoding(i2pB64alphabet)
type tBase32I2PEncoding struct{}
const base32I2PEncodingDic = "abcdefghijklmnopqrstuvwxyz234567"
var base32Encoding = base32.NewEncoding(base32I2PEncodingDic)
func (b tBase32I2PEncoding) EncodeToString(src []byte) (s string) {
s = base32Encoding.EncodeToString(src)
for s[len(s)-1] == '=' {
s = s[:len(s)-1]
}
return s
}
// Base32I2P is base32 encoding that is used for *.b32.i2p names
// It is sha256(destination key) in lowercase base32 with no padding (= characters)
var Base32I2P = tBase32I2PEncoding{}
开发者ID:cydev,项目名称:i2p,代码行数:29,代码来源:encoding.go
示例10: EncodeToString
//
// base32 encoding using I2P's alphabet
//
package base32
import (
b32 "encoding/base32"
)
var I2PEncoding *b32.Encoding = b32.NewEncoding("abcdefghijklmnopqrstuvwxyz234567")
//
// Return a go string of the I2P base32
// encoding of the provided byte slice
//
func EncodeToString(data []byte) string {
return I2PEncoding.EncodeToString(data)
}
开发者ID:majestrate,项目名称:go-i2p,代码行数:18,代码来源:base32.go
注:本文中的encoding/base32.NewEncoding函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论