Golang serve html files tutorial # 3

Golang serve html files tutorial # 3

we need two files.

  1. main.go file
  2. HTML file

to serve html files we use the following code:

tmpl, _ := template.ParseFiles(“index.html”)


package main
import (
func main() {
    tmpl, _ := template.ParseFiles("index.html")
    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        tmpl.Execute(w, nil)
    http.ListenAndServe(":8080", nil)


<html lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>GOLANG HTML</title>
    <h1>HTML PAGE</h1>
    <h2>HTML PAGE</h2>
    <h3>HTML PAGE</h3>


Tony BB

TonyBB is a Coach , marketer, hypnotist and a founder of RSKVF Production who specializes in providing simple, affordable, and easy to use solutions for Life.

Click Here to Leave a Comment Below 0 comments

Leave a Reply: