goframe框架中获取url内容并转成Base64字符串
goframe框架中获取url内容并转成Base64字符串
package toolsimport ("context""encoding/base64""github.com/gogf/gf/v2/frame/g"
)func ConvertUrlContentToBase64String(urlStr string) (base64StrContent string, err error) {ctx := context.Background()if res, err := g.Client().Get(ctx, urlStr); err != nil {return "", err} else {//contentBytes := bytes.NewBufferString(res.ReadAllString()).Bytes()contentBytes := []byte(res.ReadAllString())base64StrContent = base64.StdEncoding.EncodeToString(contentBytes)return base64StrContent, nil}
}