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

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

示例1: TestDelete

// Test the delete function.
func TestDelete(t *testing.T) {
    store := New()

    // Add some images.
    addA, _ := jpeg.Decode(base64.NewDecoder(base64.StdEncoding, strings.NewReader(imgA)))
    addB, _ := jpeg.Decode(base64.NewDecoder(base64.StdEncoding, strings.NewReader(imgB)))
    hashA, _ := CreateHash(addA)
    hashB, _ := CreateHash(addB)
    store.Add("imgA", hashA)
    store.Add("imgB", hashB)

    // Delete one.
    store.Delete("imgA")

    // Query should only return imgB.
    query, _ := jpeg.Decode(base64.NewDecoder(base64.StdEncoding, strings.NewReader(imgC)))
    queryHash, _ := CreateHash(query)
    matches := store.Query(queryHash)
    if len(matches) != 1 {
        t.Errorf("Invalid query result set size, expected 1, is %d", len(matches))
        return
    }
    if matches[0].ID != "imgB" {
        t.Errorf("Query found %s but should have found imgB", matches[0].ID)
    }
}

开发者ID:postfix,项目名称:duplo,代码行数:27,代码来源:duplo_test.go

示例2: postBuild

func postBuild(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
    if version.LessThan("1.3") {
        return fmt.Errorf("Multipart upload for build is no longer supported. Please upgrade your docker client.")
    }
    var (
        authEncoded       = r.Header.Get("X-Registry-Auth")
        authConfig        = &auth.AuthConfig{}
        configFileEncoded = r.Header.Get("X-Registry-Config")
        configFile        = &auth.ConfigFile{}
        job               = eng.Job("build")
    )

    // This block can be removed when API versions prior to 1.9 are deprecated.
    // Both headers will be parsed and sent along to the daemon, but if a non-empty
    // ConfigFile is present, any value provided as an AuthConfig directly will
    // be overridden. See BuildFile::CmdFrom for details.
    if version.LessThan("1.9") && authEncoded != "" {
        authJson := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded))
        if err := json.NewDecoder(authJson).Decode(authConfig); err != nil {
            // for a pull it is not an error if no auth was given
            // to increase compatibility with the existing api it is defaulting to be empty
            authConfig = &auth.AuthConfig{}
        }
    }

    if configFileEncoded != "" {
        configFileJson := base64.NewDecoder(base64.URLEncoding, strings.NewReader(configFileEncoded))
        if err := json.NewDecoder(configFileJson).Decode(configFile); err != nil {
            // for a pull it is not an error if no auth was given
            // to increase compatibility with the existing api it is defaulting to be empty
            configFile = &auth.ConfigFile{}
        }
    }

    if version.GreaterThanOrEqualTo("1.8") {
        job.SetenvBool("json", true)
        streamJSON(job, w, true)
    } else {
        job.Stdout.Add(utils.NewWriteFlusher(w))
    }
    job.Stdin.Add(r.Body)
    job.Setenv("remote", r.FormValue("remote"))
    job.Setenv("t", r.FormValue("t"))
    job.Setenv("q", r.FormValue("q"))
    job.Setenv("nocache", r.FormValue("nocache"))
    job.Setenv("rm", r.FormValue("rm"))
    job.SetenvJson("authConfig", authConfig)
    job.SetenvJson("configFile", configFile)

    if err := job.Run(); err != nil {
        if !job.Stdout.Used() {
            return err
        }
        sf := utils.NewStreamFormatter(version.GreaterThanOrEqualTo("1.8"))
        w.Write(sf.FormatError(err))
    }
    return nil
}

开发者ID:kraman,项目名称:docker,代码行数:58,代码来源:server.go

示例3: DecodeRFC2047Word

func DecodeRFC2047Word(s string) (string, error) {
    fields := strings.Split(s, "?")
    if len(fields) != 5 || fields[0] != "=" || fields[4] != "=" {
        return "", errors.New("mail: address not RFC 2047 encoded")
    }
    charset, encMark := strings.ToLower(fields[1]), strings.ToLower(fields[2])
    enc := text.GetEncoding(charset)
    if enc == nil {
        return "", fmt.Errorf("mail: charset not supported: %q", charset)
    }

    in := bytes.NewBufferString(fields[3])
    var r io.Reader
    switch encMark {
    case "b":
        r = base64.NewDecoder(base64.StdEncoding, in)
    case "q":
        r = qDecoder{r: in}
    default:
        return "", fmt.Errorf("mail: RFC 2047 encoding not supported: %q", encMark)
    }

    dec, err := ioutil.ReadAll(text.NewReader(r, enc))
    if err != nil {
        return "", err
    }

    return string(dec), err
}

开发者ID:rdterner,项目名称:go-1,代码行数:29,代码来源:message.go

示例4: decodeSecureCookie

func decodeSecureCookie(value string) (user string, session string, err os.Error) {
    parts := strings.Split(value, "|", 3)
    if len(parts) != 3 {
        err = os.NewError("Malformed cookie value")
        return
    }
    val := parts[0]
    timestamp := parts[1]
    sig := parts[2]
    // Check signature
    if getCookieSig([]byte(val), timestamp) != sig {
        return "", "", os.NewError("Signature error, cookie is invalid")
    }
    // Check time stamp
    ts, _ := strconv.Atoi64(timestamp)
    if ts+maxAge < time.UTC().Seconds() {
        return "", "", os.NewError("Cookie is outdated")
    }

    buf := bytes.NewBufferString(val)
    encoder := base64.NewDecoder(base64.StdEncoding, buf)
    res, _ := ioutil.ReadAll(encoder)
    str := string(res)
    lst := strings.Split(str, "!", -1)
    if len(lst) != 2 {
        return "", "", os.NewError("Missing !")
    }
    return lst[0], lst[1], nil
}

开发者ID:AaronO,项目名称:lightwave,代码行数:29,代码来源:server.go

示例5: GetSecureCookie

func (ctx *Context) GetSecureCookie(name string) (string, bool) {

    cookie, ok := ctx.Request.Cookies[name]

    if !ok {
        return "", false
    }

    parts := strings.Split(cookie, "|", 3)

    val := parts[0]
    timestamp := parts[1]
    sig := parts[2]

    if getCookieSig([]byte(val), timestamp) != sig {
        return "", false
    }

    ts, _ := strconv.Atoi64(timestamp)

    if time.Seconds()-31*86400 > ts {
        return "", false
    }

    buf := bytes.NewBufferString(val)
    encoder := base64.NewDecoder(base64.StdEncoding, buf)

    res, _ := ioutil.ReadAll(encoder)
    return string(res), true
}

开发者ID:surapaneni,项目名称:web.go,代码行数:30,代码来源:web.go

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