2019-07-19 07:39:53 +00:00
|
|
|
package internal
|
2019-07-18 14:10:43 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
)
|
|
|
|
|
2019-07-19 16:03:29 +00:00
|
|
|
var currServer *Server
|
2019-07-19 07:39:53 +00:00
|
|
|
|
2019-07-18 14:10:43 +00:00
|
|
|
type Server struct {
|
|
|
|
httpServer *http.Server
|
|
|
|
router *mux.Router
|
|
|
|
|
|
|
|
Address string
|
|
|
|
Backend Backend
|
|
|
|
}
|
|
|
|
|
|
|
|
func New() *Server {
|
|
|
|
router := mux.NewRouter()
|
|
|
|
router.HandleFunc("/_matrix/client/versions", VersionHandler)
|
|
|
|
router.HandleFunc("/_matrix/client/r0/login", LoginHandler)
|
|
|
|
router.HandleFunc("/_matrix/client/r0/logout", LogoutHandler)
|
2019-07-24 14:15:07 +00:00
|
|
|
router.HandleFunc("/_matrix/client/r0/logout/all", LogoutAllHandler)
|
2019-07-18 14:10:43 +00:00
|
|
|
router.HandleFunc("/_matrix/client/r0/register", RegisterHandler)
|
2019-07-23 14:37:02 +00:00
|
|
|
router.HandleFunc("/_matrix/client/r0/account/whoami", WhoAmIHandler)
|
2019-07-24 15:04:45 +00:00
|
|
|
router.HandleFunc("/_matrix/client/r0/joined_rooms", JoinedRoomsHandler)
|
2019-07-18 14:10:43 +00:00
|
|
|
router.HandleFunc("/_matrix/client/r0/sync", SyncHandler)
|
|
|
|
router.HandleFunc("/", RootHandler)
|
|
|
|
|
|
|
|
httpServer := new(http.Server)
|
2019-07-19 07:45:11 +00:00
|
|
|
httpServer.Addr = ":8008"
|
2019-07-18 14:10:43 +00:00
|
|
|
httpServer.Handler = router
|
|
|
|
|
|
|
|
server := &Server{
|
|
|
|
httpServer: httpServer,
|
|
|
|
router: router}
|
|
|
|
|
2019-07-19 16:03:29 +00:00
|
|
|
currServer = server
|
2019-07-18 14:10:43 +00:00
|
|
|
return server
|
|
|
|
}
|
|
|
|
|
|
|
|
func (server *Server) Run() error {
|
|
|
|
return server.httpServer.ListenAndServe() // TODO: custom port
|
|
|
|
}
|