Opening an image directly from URL

i would like to open an image file from a url directly without downloading it, however cant seem to find libraries that would help me do that. my package code till now is below

package browser

import (

type Reddit struct {
   Kind string `json:"kind"`
   Data Data   `json:"data"`
type Source struct {
   URL    string `json:"url"`
   Width  int    `json:"width"`
   Height int    `json:"height"`
type Content struct {
   Selftext string `json:"selftext"`
   Title    string `json:"title"`
   Downs    int    `json:"downs"`
   Ups      int    `json:"ups"`
   Score    int    `json:"score"`
   URL      string `json:"url"`
type Children struct {
   Kind string  `json:"kind"`
   Data Content `json:"data"`
type Data struct {
   Children []Children `json:"children"`
//HTTPRequestCustomUserAgent bla bla
func HTTPRequestCustomUserAgent(url, userAgent string) (b []byte, err error) {
   req, err := http.NewRequest("GET", url, nil)
   if err != nil {

   req.Header.Set("User-Agent", userAgent)

   client := &http.Client{}
   resp, err := client.Do(req)
   if err != nil {
   defer resp.Body.Close()

   if resp.StatusCode != 200 {
   	err = errors.New(
   		"resp.StatusCode: " +

   return ioutil.ReadAll(resp.Body)

func Parse(url string) {

   var reddit Reddit
   b, err := HTTPRequestCustomUserAgent(url, "Mozilla")
   if err != nil {
   json.Unmarshal([]byte(b), &reddit)
   for i := 0; i < len(reddit.Data.Children); i++ {

   	text := string(reddit.Data.Children[i].Data.Selftext)
   	img := string(reddit.Data.Children[i].Data.URL)

   	fmt.Println("Title :", reddit.Data.Children[i].Data.Title)
   	fmt.Println("Upvots :", reddit.Data.Children[i].Data.Ups)
   	fmt.Println("Downvotes :", reddit.Data.Children[i].Data.Downs)
   	if text == "" {
   		fmt.Println("Content :", img)
   	} else {
   		fmt.Println("Content :", text)

I would like to open the image content in my default image viewer directly from the URL.
Thanks in advance

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.