2016-09-17 9 views
-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

答えて

0

あるんホリネズミたるみチャットに助けられました、一時変数を作成する必要があります

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

実際に一時変数は必要ありません。正しいタイプが必要です。APIドキュメントではhttps:// golangと言います。 org/pkg/encoding/base64 /#Encoding.DecodeString 'base64.StdEncoding.DecodeString'は文字列ではなく' [] byte'スライスを返します。 –

+1

そうだけど、私がそれを変更しても空であれば、それを後の全体的なプログラムのためのポインタにしようとしている。 – nadermx

+0

バイトスライスの標準値はnil AFAIKです。まさにあなたが話しているものですね。 –

関連する問題