package main import ( "2PPS/client" "fmt" "log" "net/http" "os" ) var Port = ":3000" func main() { f, err := os.OpenFile("evalDataClient", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) if err != nil { log.Fatalf("error opening file: %v", err) } defer f.Close() log.SetOutput(f) if os.Args[len(os.Args)-1] == "1" { go client.Client(0, f) } http.HandleFunc("/", ServeFiles) fmt.Println("Serving @ : ", "http://127.0.0.1"+Port) log.Fatal(http.ListenAndServe(Port, nil)) } func ServeFiles(w http.ResponseWriter, r *http.Request) { switch r.Method { case "GET": path := r.URL.Path //fmt.Println("path before: ", path) if path == "/" { path = "index.html" } else { path = "/home/simon/goCode/AnonymousTopicBasedPubSubCommunicationforMicroblogging" + path } //fmt.Println("path after: ", path) http.ServeFile(w, r, path) case "POST": r.ParseMultipartForm(0) message := r.FormValue("message") fmt.Println("----------------------------------") fmt.Println("Tweet to post: ", message) client.SetGuiTweet(message) case "getTweets": r.ParseMultipartForm(0) fmt.Fprint(w, client.GetTweets(0)) case "getArchiveTweets": r.ParseMultipartForm(0) fmt.Fprint(w, client.GetTweets(1)) case "updateMainTopicList": r.ParseMultipartForm(0) fmt.Println("updateMainTopicList") case "updateMainInterests": r.ParseMultipartForm(0) fmt.Println("updateMainInterests") case "updateArchiveTopicList": r.ParseMultipartForm(0) fmt.Println("updateArchiveTopicList") case "updateArchiveInterests": r.ParseMultipartForm(0) fmt.Println("updateArchiveInterests") default: fmt.Fprintf(w, "Request type not supported") } }