Tuesday, April 22, 2025
HomeGolangHow one can present image in html web page by -...

How one can present image in html web page by – Getting Assist


I construct a quite simple net through the use of GO and HTML.

The hierarchy is like this…

root |--html
     |--static---gambar

The folder of ‘html’ comprises my html-code (sementara.html). The folder of ‘static’ comprises the folder of ‘gambar’. And within the folder of ‘gambar’ comprises the picture-file (gua.png).

===
sementara.html

<html>
<head>
<title>Present photo-list</title>
</head>
<fashion>
  	a {
  		text-decoration: none;
  	}
  	
  	physique {
  		font-family: Arial, Helvetica;
  		font-size: 12px;
	}
</fashion>
<physique><middle>
<h1>Picture-Checklist</h1>
				<a href="https://discussion board.golangbridge.org/t/how-to-show-picture-in-html-page-by-img-src/imgsrcgua" fashion="text-decoration: none;"><img src="../static/gambar/gua.png" alt="I cannot discover the picture-file">Patrix Linus</a>
</middle></physique>
</html>

![image|690x156](add://5IxhOM57bOFyoerlQfJmCt9YHh0.png)
![image|566x146](add://nqzeDKaOP8FpAAAwVpWo7fRd3JW.png)


====
foremost.go

package deal foremost

import (
	"fmt"
	"html/template"
	"log"
	"web/http"

	//"web/url"

	//"os"
	"strings"
)

func my_webLobby(w http.ResponseWriter, r *http.Request) {
	r.ParseForm()
	fmt.Println(r.Type)
	fmt.Println("path", r.URL.Path)
	fmt.Println("scheme", r.URL.Scheme)
	fmt.Println(r.Type["url_long"])
	for okay, v := vary r.Type {
		fmt.Println("key:", okay)
		fmt.Println("val:", strings.Be a part of(v, ""))
	}

	t, _ := template.ParseFiles("html/sementara.html")
	t.Execute(w, nil)
}

func tampilkanimgsrc(w http.ResponseWriter, r *http.Request) {
	http.Redirect(w, r, "https://discussion board.golangbridge.org/", 302)
}

func foremost() {
	http.HandleFunc("https://discussion board.golangbridge.org/", my_webLobby)
	http.HandleFunc("/imgsrcgua", tampilkanimgsrc)

	err := http.ListenAndServe(":9099", nil)
	if err != nil {
		log.Deadly("ListenAndServe: ", err)
	}
}

=====

However my ‘sementara.html’ cannot discover the file of ‘gua.png’(an image).

I don’t perceive why. Please clarify to me how truly GO manages about location of a file. Why my html cannot discover the file of image (‘gua.png’) whereas it must be in .

Please any person could be so good expain this concern to me.

The request for the picture shall be routed to my_webLobby and in there may be nothing to load the file.
You can add one thing like
http.Deal with("/static/", http.FileServer(http.Dir(".")))

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments