-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
76 lines (69 loc) · 2.25 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
package main
import (
"AltTube-Go/auth"
"AltTube-Go/database"
docs "AltTube-Go/docs"
"AltTube-Go/handlers"
"AltTube-Go/handlers/like_video_handlers"
"AltTube-Go/handlers/piped_handlers"
"AltTube-Go/handlers/piped_handlers/opensearch"
"AltTube-Go/handlers/pipedproxy"
"AltTube-Go/handlers/user_handlers"
"AltTube-Go/handlers/user_handlers/devices"
"github.com/gin-gonic/gin"
swaggerfiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
"log"
"os"
)
var r *gin.Engine
// @title AltTube API
// @version 1.0
// @description This is the API documentation for the AltTube application.
// @SecurityDefinitions.apiKey AccessToken
// @in header
// @name Authorization
// @SecurityDefinitions.apiKey RefreshToken
// @in header
// @name Authorization
func main() {
database.Init()
startApi()
}
func startApi() {
r = gin.Default()
docs.SwaggerInfo.BasePath = "/"
r.GET("/ping", handlers.Ping)
pipedApi := r.Group("/piped")
{
pipedApi.GET("/opensearch/suggestions", opensearch.Suggestions)
pipedApi.GET("/search", piped_handlers.Search)
pipedApi.GET("/streams/:videoID", piped_handlers.Streams)
}
pipedProxyApi := r.Group("/pipedproxy")
{
pipedProxyApi.GET("/*action", pipedproxy.PipedProxy)
}
userApi := r.Group("/user")
{
userApi.POST("/login", user_handlers.Login)
userApi.POST("/signup", user_handlers.Signup)
userApi.PATCH("/email", auth.Middleware(), user_handlers.EditEmail)
userApi.DELETE("/", auth.Middleware(), user_handlers.DeleteUser)
userApi.POST("/logout", auth.Middleware(), user_handlers.LogoutUser)
userApi.POST("/refresh_token", user_handlers.RefreshToken)
userApi.GET("/devices", auth.Middleware(), devices.GetDevices)
userApi.DELETE("/devices", auth.Middleware(), devices.DeleteDevices)
}
likeApi := r.Group("/like")
{
likeApi.GET("/:videoID", auth.Middleware(), like_video_handlers.GetLikeVideo)
likeApi.POST("/:videoID", auth.Middleware(), like_video_handlers.AddLikeVideo)
likeApi.DELETE("/:videoID", auth.Middleware(), like_video_handlers.RemoveLikeVideo)
likeApi.GET("/", auth.Middleware(), like_video_handlers.GetLikedVideos)
}
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))
if err := r.Run(":" + os.Getenv("PORT")); err != nil {
log.Fatalf("API failed to start: %v", err)
}
}