123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- package main
- import (
- "2PPS/client"
- "encoding/json"
- "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
- if path == "/" {
- path = "index.html"
- } else {
- path = "/home/simon/goCode/AnonymousTopicBasedPubSubCommunicationforMicroblogging" + path
- }
- http.ServeFile(w, r, path)
- case "POST":
- r.ParseMultipartForm(0)
- tweet := r.FormValue("message")
- fmt.Println("Tweet to post: ", tweet)
- client.SetGuiTweet(tweet)
- 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.Fprint(w, client.GetTopicList(0))
- case "updateMainInterests":
- var x struct {
- Topics []string `json:"mainTopics"`
- }
- if err := json.NewDecoder(r.Body).Decode(&x); err != nil {
- panic(err)
- }
- topicsToGo := x.Topics
- client.UpdateInterests(topicsToGo, 0)
- case "updateArchiveTopicList":
- r.ParseMultipartForm(0)
- fmt.Fprint(w, client.GetTopicList(1))
- case "updateArchiveInterests":
- var x struct {
- Topics []string `json:"archiveTopics"`
- }
- if err := json.NewDecoder(r.Body).Decode(&x); err != nil {
- panic(err)
- }
- topicsToGo := x.Topics
- client.UpdateInterests(topicsToGo, 1)
- default:
- fmt.Fprintf(w, "Request type not supported")
- }
- }
|