/
main.go
79 lines (65 loc) · 2.37 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"SocialWebsite/config"
"SocialWebsite/controllers"
"fmt"
"gopkg.in/confluentinc/confluent-kafka-go.v1/kafka"
"log"
"net/http"
"time"
)
func main() {
//Spins up go func for listening to producer events
//This should work
// go func() {
// // //Infinite for loop to have this run forever and check events as they come in
// // //Good for small scale
// // //Bad for large scale
// for {
// for e := range config.Producer.Events() {
// switch ev := e.(type) {
// case *kafka.Message:
// if ev.TopicPartition.Error != nil {
// //Prints to file if delivery failed
// _, err := fmt.Fprintf(config.FileForKafka, "Delivery failed: %v\n", ev.TopicPartition)
// if err != nil {
// log.Println(err, "Failed to write Kafka Delivery Failed to file")
// }
// } else {
// //Prints to file if delivery success
// _, err := fmt.Fprintf(config.FileForKafka, "Delivered message to %v\n", ev.TopicPartition)
// if err != nil {
// log.Println(err, "Failed to write Kafka Delivery Success to file")
// }
// }
// }
// }
// time.Sleep(time.Second)
// }
// }()
//Servers Main Pages
http.HandleFunc("/", controllers.Index)
http.HandleFunc("/login", controllers.Login)
http.HandleFunc("/loginPost", controllers.LoginPost)
http.HandleFunc("/signup", controllers.Signup)
http.HandleFunc("/logout", controllers.Logout)
http.Handle("/favicon.ico", http.NotFoundHandler())
//Servers Upload/Posts
http.HandleFunc("/uploadpost", controllers.UploadPageServe)
http.HandleFunc("/submitUploadPost", controllers.UploadPost)
http.HandleFunc("/yourPosts", controllers.YourPosts)
//Liking/Unliking Posts
http.HandleFunc("/likePost", controllers.LikePost)
http.HandleFunc("/unlikePost", controllers.UnlikePost)
http.HandleFunc("/likedPosts", controllers.LikedPostPage)
//DeletingPosts
http.HandleFunc("/deletePost", controllers.DeletePost)
//Searching for other users/posts
http.HandleFunc("/findPosts", controllers.FindUser)
//Session Cleaning Testing
http.HandleFunc("/cleansess", controllers.CleanSessions)
//Serves CSS used by HTML when executing Templates
http.Handle("/styles/", http.StripPrefix("/styles/", http.FileServer(http.Dir("./templates/styles/"))))
http.Handle("/js/", http.StripPrefix("/js/", http.FileServer(http.Dir("./templates/js/"))))
http.ListenAndServe(":80", nil)
}