Created
July 31, 2017 22:04
-
-
Save JKobyP/7cd29579033b4f35749b087a6410f35b to your computer and use it in GitHub Desktop.
This file contains 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
import ( | |
"net/http" | |
"log" | |
) | |
func main() { | |
http.Handle("/", reactServer()) | |
http.Handle("/dist/", assetHandler()) | |
http.HandleFunc("/api/", apiHandler) | |
api.Init() | |
log.Fatal(http.ListenAndServe(":8000", nil)) | |
} | |
func assetHandler() http.Handler { | |
return http.FileServer(http.Dir(".")) | |
} | |
func reactServer() http.Handler { | |
fn := func(w http.ResponseWriter, r *http.Request) { | |
http.ServeFile(w, r, "index.html") | |
log.Printf("Serving index.html") | |
} | |
return http.HandlerFunc(fn) | |
} | |
func apiHandler(w http.ResponseWriter, req *http.Request) { | |
cmd := req.URL.Path[len("/api/"):] | |
if cmd[0:2] == "pr" { | |
PRHandler(w, req) | |
} else { | |
fmt.Fprintf(w, "Support for %v not implemented!\n", cmd) | |
log.Printf("Support for %v not implemented!\n", cmd) | |
} | |
} | |
func PRHandler(w http.ResponseWriter, req *http.Request) { | |
components := strings.Split(req.URL.Path[len("/api/pr/"):], "/") | |
if len(components) != 2 { | |
log.Printf("invalid url %s", req.URL.Path) | |
return | |
} | |
// etc. etc. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment