1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- 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)
- 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("Message from Client: ", message)
- client.SetGuiTweet(message)
- // respond to client's request, dont think i need this
- //fmt.Fprintf(w, "Server: %s \n", message+" | "+time.Now().Format(time.RFC3339))
- default:
- fmt.Fprintf(w, "Request type other than GET or POST not supported")
- }
- }
|