()
| 31 | ) |
| 32 | |
| 33 | func main() { |
| 34 | fmt.Println("[Server]") |
| 35 | |
| 36 | // Establish a Rabbit connection. |
| 37 | connMQ, err := rabbit.GetConn(conf.RabbitURL) |
| 38 | if err != nil { |
| 39 | log.Fatalf("rabbit connection: %s", err) |
| 40 | } |
| 41 | defer connMQ.Close() |
| 42 | |
| 43 | err = connMQ.DeclareTopicExchange(conf.Exchange) |
| 44 | if err != nil { |
| 45 | log.Fatalf("declare exchange: %s", err) |
| 46 | } |
| 47 | |
| 48 | // Redis connection |
| 49 | connR := redis.NewClient(&redis.Options{ |
| 50 | Addr: conf.RedisURL, |
| 51 | Password: "", // no password set |
| 52 | DB: 0, // use default DB |
| 53 | }) |
| 54 | |
| 55 | http.Handle("/static/", http.FileServer(http.FS(filesStatic))) |
| 56 | http.HandleFunc("/", handleHome) |
| 57 | http.HandleFunc("/messages", handleMessages(connR)) |
| 58 | http.HandleFunc("/ws", handleWebsocketConn(connMQ)) |
| 59 | http.HandleFunc("/api/cache", handleAPICache(connR)) // defined in api.go |
| 60 | log.Fatal(http.ListenAndServe(conf.ServerAddr, nil)) |
| 61 | } |
| 62 | |
| 63 | // handleHome handles the home page. |
| 64 | func handleHome(w http.ResponseWriter, r *http.Request) { |
nothing calls this directly
no test coverage detected