I'm running an http server instance with Go and I would like to return the HTML doc to a client, but the JS and the CSS files are not working. How do I make the JS and CSS get sent along with the HTML if they are in different files?
Go Code
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
func handler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html")
file, _ := ioutil.ReadFile("webpage.html")
s := string(file)
fmt.Fprintf(w, s)
}
webpage.html
html fileClick to change color
And changeColor.js
function init(){
var h1tags = document.getElementsByTagName("h1");
h1tags[0].onclick = changeColor;
}
function changeColor(){
this.style.color = '#000000';
}
onload = init;
CSS is in a file called styles.css in the same directory as the HTML doc.