不能在赋值时使用& dashUrl(类型* [] byte)作为类型* string

时间:2016-09-17 20:59:39

标签: go

我正在尝试解析可能为空的表单帖子,如果是,我将更改变量。尝试使用*string类型。我遇到的问题是它不会转换为dashUrl,而是转换为start_time

package main

import (
    "encoding/base64"
    "strconv"
    "github.com/gocraft/web"
)

type YoutubeContext struct {
    StartTime *float64 `json:"start_time"`
    DashUrl   *string  `json:"dash_url"`
}

func (c *YoutubeContext) SetYoutubeContext(rw web.ResponseWriter, req *web.Request, next web.NextMiddlewareFunc) {
    if f, err := strconv.ParseFloat(req.FormValue("start_time"), 64); err == nil {
        c.StartTime = &f
    }
    if dashUrl, dashUrlDecodeErr := base64.StdEncoding.DecodeString(req.FormValue("dash_url")); dashUrlDecodeErr == nil {
        c.DashUrl = &dashUrl

    }

}
func main() {

}

它显示的错误是

./test.go:19: cannot use &dashUrl (type *[]byte) as type *string in assignment

1 个答案:

答案 0 :(得分:0)

帮助了地鼠闲聊,需要做一个临时变量

blah := string(dashUrl)
c.DashUrl = &blah