Last active
February 17, 2020 13:49
-
-
Save superbrothers/0a8b6390c6315916aeb8 to your computer and use it in GitHub Desktop.
Simple Web Server with golang
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io/ioutil" | |
"log" | |
"net/http" | |
) | |
func rootHandler(w http.ResponseWriter, r *http.Request) { | |
w.Header().Set("Content-Type", "text/html") | |
w.WriteHeader(http.StatusOK) | |
data, err := ioutil.ReadFile("index.html") | |
if err != nil { | |
panic(err) | |
} | |
w.Header().Set("Content-Length", fmt.Sprint(len(data))) | |
fmt.Fprint(w, string(data)) | |
} | |
func main() { | |
http.HandleFunc("/", rootHandler) | |
log.Fatal(http.ListenAndServe(":8080", nil)) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Hello world</h1> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When I try to compile this program I get the following messages (windows10 command prompt):
..\src\net\http\transport.go:15:2: cannot find package "container/list" in any of:
C:\installed programs\go\src\vendor\container\list (vendor tree)
C:\installed programs\go\src\container\list (from $GOROOT)
C:\installed programs\go\temp\src\container\list (from $GOPATH)
I have no problem running programs that don't use http. So what does this mean?
Thanks!