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

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

示例1: readConfig

// reads the configuration file from the path specified by
// the config command line flag.
func readConfig(configFile string) error {
    b, err := ioutil.ReadFile(configFile)
    if err != nil {
        return err
    }
    err = json.Unmarshal(b, &config)
    if err != nil {
        return err
    }
    cookieAuthKey, err = hex.DecodeString(*config.CookieAuthKeyHexStr)
    if err != nil {
        return err
    }
    cookieEncrKey, err = hex.DecodeString(*config.CookieEncrKeyHexStr)
    if err != nil {
        return err
    }
    secureCookie = securecookie.New(cookieAuthKey, cookieEncrKey)
    // verify auth/encr keys are correct
    val := map[string]string{
        "foo": "bar",
    }
    _, err = secureCookie.Encode(cookieName, val)
    if err != nil {
        // for convenience, if the auth/encr keys are not set,
        // generate valid, random value for them
        auth := securecookie.GenerateRandomKey(32)
        encr := securecookie.GenerateRandomKey(32)
        fmt.Printf("auth: %s\nencr: %s\n", hex.EncodeToString(auth), hex.EncodeToString(encr))
    }
    // TODO: somehow verify twitter creds
    return err
}

开发者ID:uwydoc,项目名称:web-blog,代码行数:35,代码来源:main.go

示例2: TestAmqp_GetEmptyMethod

func TestAmqp_GetEmptyMethod(t *testing.T) {
    if testing.Verbose() {
        logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"amqp", "amqpdetailed"})
    }

    amqp := amqpModForTests()
    amqp.sendRequest = true

    data, err := hex.DecodeString("01000100000013003c004600000b526f626269" +
        "654b65616e6501ce")
    assert.Nil(t, err)
    data2, err := hex.DecodeString("01000100000005003c004800ce")
    assert.Nil(t, err)

    tcptuple := testTCPTuple()

    req := protos.Packet{Payload: data}
    private := protos.ProtocolData(new(amqpPrivateData))
    private = amqp.Parse(&req, tcptuple, 0, private)
    req = protos.Packet{Payload: data2}
    amqp.Parse(&req, tcptuple, 1, private)

    trans := expectTransaction(t, amqp)
    assert.Equal(t, "basic.get-empty", trans["method"])
    assert.Equal(t, "basic.get RobbieKeane", trans["request"])
    assert.Equal(t, "amqp", trans["type"])
    assert.Equal(t, common.OK_STATUS, trans["status"])
}

开发者ID:ruflin,项目名称:beats,代码行数:28,代码来源:amqp_test.go

示例3: TestAmqp_RecoverMethod

func TestAmqp_RecoverMethod(t *testing.T) {
    if testing.Verbose() {
        logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"amqp", "amqpdetailed"})
    }

    amqp := amqpModForTests()
    amqp.sendRequest = true

    data, err := hex.DecodeString("01000100000005003c006e01ce")
    assert.Nil(t, err)
    data2, err := hex.DecodeString("01000100000004003c006fce")
    assert.Nil(t, err)

    tcptuple := testTCPTuple()

    req := protos.Packet{Payload: data}
    private := protos.ProtocolData(new(amqpPrivateData))
    private = amqp.Parse(&req, tcptuple, 0, private)
    req = protos.Packet{Payload: data2}
    amqp.Parse(&req, tcptuple, 1, private)

    trans := expectTransaction(t, amqp)
    assert.Equal(t, "basic.recover", trans["method"])
    assert.Equal(t, "basic.recover", trans["request"])
    assert.Equal(t, "amqp", trans["type"])
    assert.Equal(t, common.OK_STATUS, trans["status"])
    assert.Equal(t, common.MapStr{"requeue": true}, trans["amqp"])
}

开发者ID:ruflin,项目名称:beats,代码行数:28,代码来源:amqp_test.go

示例4: Bond

func Bond(nodeAddr, pubkey, unbondAddr, amtS, nonceS string) (*types.BondTx, error) {
    pub, addrBytes, amt, nonce, err := checkCommon(nodeAddr, pubkey, "", amtS, nonceS)
    if err != nil {
        return nil, err
    }
    var pubKey account.PubKeyEd25519
    var unbondAddrBytes []byte

    if unbondAddr == "" {
        pkb, _ := hex.DecodeString(pubkey)
        copy(pubKey[:], pkb)
        unbondAddrBytes = pubKey.Address()
    } else {
        unbondAddrBytes, err = hex.DecodeString(unbondAddr)
        if err != nil {
            return nil, fmt.Errorf("unbondAddr is bad hex: %v", err)
        }

    }

    tx, err := types.NewBondTx(pub)
    if err != nil {
        return nil, err
    }
    _ = addrBytes
    tx.AddInputWithNonce(pub, amt, int(nonce))
    tx.AddOutput(unbondAddrBytes, amt)

    return tx, nil
}

开发者ID:GetLevvel,项目名称:blockchain-digital-notary,代码行数:30,代码来源:core.go

示例5: TestAmqp_ConnectionCloseNoError

func TestAmqp_ConnectionCloseNoError(t *testing.T) {
    if testing.Verbose() {
        logp.LogInit(logp.LOG_DEBUG, "", false, true, []string{"amqp", "amqpdetailed"})
    }

    amqp := amqpModForTests()
    amqp.hideConnectionInformation = false

    data, err := hex.DecodeString("01000000000012000a003200c8076b74687862616900000000ce")
    assert.Nil(t, err)
    data2, err := hex.DecodeString("01000000000004000a0033ce")
    assert.Nil(t, err)

    tcptuple := testTCPTuple()

    req := protos.Packet{Payload: data}
    private := protos.ProtocolData(new(amqpPrivateData))
    private = amqp.Parse(&req, tcptuple, 0, private)
    req = protos.Packet{Payload: data2}
    amqp.Parse(&req, tcptuple, 1, private)

    trans := expectTransaction(t, amqp)
    assert.Equal(t, "connection.close", trans["method"])
    assert.Equal(t, "amqp", trans["type"])
    assert.Equal(t, common.OK_STATUS, trans["status"])
    assert.Nil(t, trans["notes"])

    fields, ok := trans["amqp"].(common.MapStr)
    assert.True(t, ok)
    code, ok := fields["reply-code"].(uint16)
    assert.True(t, ok)
    assert.Equal(t, uint16(200), code)
}

开发者ID:ruflin,项目名称:beats,代码行数:33,代码来源:amqp_test.go

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