-1
空である可能性のある郵便ポストを解析しようとしています。使用しようとしている*string
タイプです。私がいる問題は、それがdashUrl
用変換dosen'tですがstart_time
タイプとして*&dashUrl(タイプ* []バイト)を使用できません*割り当ての文字列
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
実際に一時変数は必要ありません。正しいタイプが必要です。APIドキュメントではhttps:// golangと言います。 org/pkg/encoding/base64 /#Encoding.DecodeString 'base64.StdEncoding.DecodeString'は文字列ではなく' [] byte'スライスを返します。 –
そうだけど、私がそれを変更しても空であれば、それを後の全体的なプログラムのためのポインタにしようとしている。 – nadermx
バイトスライスの標準値はnil AFAIKです。まさにあなたが話しているものですね。 –