Last active
November 9, 2018 20:19
-
-
Save ki4jnq/1b3096f1bf0626267a5bf0c29c519f5c to your computer and use it in GitHub Desktop.
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 web | |
import ( | |
"net/http" | |
"encoding/json" | |
) | |
func ServerStart() { | |
http.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) { | |
buf, err := json.Marshal(map[string]string{"message": "Hello World!"}) | |
if err != nil { | |
res.Write([]byte("Boom!")) | |
panic(err) | |
} | |
res.Header().Set("Content-Type", "application/json") | |
res.Write(buf) | |
}) | |
http.ListenAndServe( | |
":8081", | |
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
package main | |
import ( | |
"fmt" | |
"github.com/yourname/web" | |
) | |
func main() { | |
fmt.Println("Starting Server...") | |
web.ServerStart() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment