How do you serve a static html file using a go web server?

后端 未结 4 428
难免孤独
难免孤独 2020-12-04 06:34

How do you serve index.html (or some other static HTML file) using a go web server?

I just want a basic, static HTML file (like an article, for example) which I can

4条回答
  •  不知归路
    2020-12-04 06:49

    This is easy in golang as:

    package main
    
    import (
        "log"
        "net/http"
    )
    
    func main() {
        log.Fatal(http.ListenAndServe(":8080", http.FileServer(http.Dir("."))))
    }
    

    `

    You can just do this and make sure to keep your HTML file as index.html

提交回复
热议问题