2017-05-05 16:39:15 +02:00
package router
import (
"github.com/gorilla/mux"
"net/http"
)
var Router * mux . Router
2017-05-06 00:37:59 +02:00
func init ( ) {
2017-05-05 16:39:15 +02:00
Router = mux . NewRouter ( )
2017-05-07 00:26:02 +02:00
cssHandler := http . FileServer ( http . Dir ( "./public/css/" ) )
jsHandler := http . FileServer ( http . Dir ( "./public/js/" ) )
imgHandler := http . FileServer ( http . Dir ( "./public/img/" ) )
2017-05-07 00:27:26 +02:00
http . Handle ( "/css/" , http . StripPrefix ( "/css/" , cssHandler ) )
http . Handle ( "/js/" , http . StripPrefix ( "/js/" , jsHandler ) )
http . Handle ( "/img/" , http . StripPrefix ( "/img/" , imgHandler ) )
2017-05-05 16:39:15 +02:00
// Routes,
Router . HandleFunc ( "/" , HomeHandler ) . Name ( "home" )
Router . HandleFunc ( "/page/{page:[0-9]+}" , HomeHandler ) . Name ( "home_page" )
Router . HandleFunc ( "/search" , SearchHandler ) . Name ( "search" )
Router . HandleFunc ( "/search/{page}" , SearchHandler ) . Name ( "search_page" )
Router . HandleFunc ( "/api/{page}" , ApiHandler ) . Methods ( "GET" )
Router . HandleFunc ( "/api/view/{id}" , ApiViewHandler ) . Methods ( "GET" )
Router . HandleFunc ( "/faq" , FaqHandler ) . Name ( "faq" )
2017-05-06 00:37:59 +02:00
Router . HandleFunc ( "/feed" , RssHandler ) . Name ( "feed" )
2017-05-05 16:39:15 +02:00
Router . HandleFunc ( "/view/{id}" , ViewHandler ) . Name ( "view_torrent" )
2017-05-06 10:36:37 +02:00
Router . HandleFunc ( "/upload" , UploadHandler ) . Name ( "upload" )
2017-05-07 05:04:55 +02:00
Router . HandleFunc ( "/user/register" , UserRegisterFormHandler ) . Name ( "user_register" ) . Methods ( "GET" )
Router . HandleFunc ( "/user/login" , UserLoginFormHandler ) . Name ( "user_login" ) . Methods ( "GET" )
Router . HandleFunc ( "/user/register" , UserRegisterPostHandler ) . Name ( "user_register" ) . Methods ( "POST" )
2017-05-07 08:59:45 +02:00
2017-05-07 09:05:31 +02:00
Router . NotFoundHandler = http . HandlerFunc ( NotFoundHandler )
2017-05-06 00:37:59 +02:00
}