Files
discord-retokenizer/endpoints/endpoints.go
2022-12-11 01:20:21 -06:00

49 lines
1.5 KiB
Go

package endpoints
import (
"time"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
)
func Run() {
r := gin.Default()
r.Use(cors.New(cors.Config{
AllowOrigins: []string{"http://localhost:4000"},
AllowMethods: []string{"GET", "POST", "DELETE", "PATCH"},
AllowHeaders: []string{"Origin", "Content-Type"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
AllowOriginFunc: func(origin string) bool {
return origin == "http://localhost:4000"
},
MaxAge: 12 * time.Hour,
}))
public := r.Group("/")
public.POST("/login", login) //web login
public.GET("/access", access) //access token
private := r.Group("/")
private.Use(userIsAuthorized)
private.PATCH("/login", updateLogin) //change username/password (required before adding bots)
private.GET("/login/tokens", getLoginTokens) //list of login tokens
private.DELETE("/login/tokens", clearLoginTokens) //clears all login tokens
private.GET("/bots", bots) //generalized list of bots
private.GET("/bot/:id", bot) //specific bot
private.POST("/bot", addBot) //add bot given token
private.DELETE("/bot/:id", removeBot) //remove bot
private.GET("/tokens", getTokens) //generalized list of tokens
private.GET("/token/:id", getToken) //specific token
private.POST("/token", addToken) //new token given bot (so you cant add a token if theres no bots)
private.DELETE("/token/:id", deleteToken) //remove token
private.PATCH("/token/:id", updateToken) //update token given bot
r.Run()
}