added golang http url routing
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -7,3 +7,8 @@ acecore
|
|||||||
|
|
||||||
# Logging
|
# Logging
|
||||||
logs/
|
logs/
|
||||||
|
|
||||||
|
# Web
|
||||||
|
|
||||||
|
web/key.pem
|
||||||
|
web/cert.pem
|
@@ -13,7 +13,7 @@ var color map[string]string = map[string]string{
|
|||||||
"primary": "#211951",
|
"primary": "#211951",
|
||||||
}
|
}
|
||||||
|
|
||||||
var Gh_url string = "https://github.com/vaporvee/acecore/blob/main/"
|
const Gh_url string = "https://github.com/vaporvee/acecore/blob/main/"
|
||||||
|
|
||||||
func GetColor(s string) int {
|
func GetColor(s string) int {
|
||||||
hexColor := strings.TrimPrefix(color[s], "#")
|
hexColor := strings.TrimPrefix(color[s], "#")
|
||||||
|
1
custom/privacy.html
Symbolic link
1
custom/privacy.html
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
web/html/privacy.html
|
1
custom/tos.html
Symbolic link
1
custom/tos.html
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
web/html/tos.html
|
2
main.go
2
main.go
@@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/vaporvee/acecore/log2webhook"
|
"github.com/vaporvee/acecore/log2webhook"
|
||||||
|
"github.com/vaporvee/acecore/web"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -70,6 +71,7 @@ func main() {
|
|||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
}
|
}
|
||||||
logrus.Infof("Bot is now running as '%s'!", app.Bot.Username)
|
logrus.Infof("Bot is now running as '%s'!", app.Bot.Username)
|
||||||
|
go web.HostRoutes(app.Bot.ID.String())
|
||||||
|
|
||||||
sc := make(chan os.Signal, 1)
|
sc := make(chan os.Signal, 1)
|
||||||
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
|
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
|
||||||
|
@@ -1,23 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<meta http-equiv="refresh" content="0; url=https://discord.com/oauth2/authorize?client_id=1216816348433219644" />
|
|
||||||
<title>acecore</title>
|
|
||||||
</head>
|
|
||||||
<style>
|
|
||||||
a {
|
|
||||||
color: #212121;
|
|
||||||
}
|
|
||||||
|
|
||||||
body {
|
|
||||||
background-color: black;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<p><a href="https://discord.com/oauth2/authorize?client_id=1216816348433219644">Redirect</a></p>
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
53
web/web.go
Normal file
53
web/web.go
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
package web
|
||||||
|
|
||||||
|
import (
|
||||||
|
"embed"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"text/template"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
"github.com/vaporvee/acecore/custom"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Embed the HTML file into the binary
|
||||||
|
//
|
||||||
|
//go:embed html/privacy.html
|
||||||
|
var privacyHTML embed.FS
|
||||||
|
|
||||||
|
//go:embed html/tos.html
|
||||||
|
var tosHTML embed.FS
|
||||||
|
|
||||||
|
func handleHTML(w http.ResponseWriter, embed embed.FS, path string) {
|
||||||
|
tmpl, err := template.ParseFS(embed, path)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
tmpl.Execute(w, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func HostRoutes(botID string) {
|
||||||
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
http.Redirect(w, r, custom.Gh_url, http.StatusMovedPermanently)
|
||||||
|
})
|
||||||
|
http.HandleFunc("/invite", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
http.Redirect(w, r, "https://discord.com/oauth2/authorize?client_id="+botID, http.StatusMovedPermanently)
|
||||||
|
})
|
||||||
|
http.HandleFunc("/privacy", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
handleHTML(w, privacyHTML, "./html/privacy.html")
|
||||||
|
})
|
||||||
|
http.HandleFunc("/tos", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
handleHTML(w, tosHTML, "./html/tos.html")
|
||||||
|
})
|
||||||
|
|
||||||
|
server := &http.Server{
|
||||||
|
Addr: ":443",
|
||||||
|
Handler: nil,
|
||||||
|
ErrorLog: log.New(nil, "", 0),
|
||||||
|
}
|
||||||
|
logrus.Info("Starting server for html routes on :443...")
|
||||||
|
if err := server.ListenAndServeTLS("./web/cert.pem", "./web/key.pem"); err != nil {
|
||||||
|
logrus.Errorf("Error starting server: %v\n", err)
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user