cert400/cmd/serverFunc.go

39 lines
663 B
Go
Raw Normal View History

2024-05-22 10:42:00 +02:00
package cmd
import (
"embed"
"fmt"
"github.com/gin-gonic/gin"
2024-05-22 15:02:58 +02:00
"net/http"
2024-05-22 10:42:00 +02:00
)
var (
listenPort = "1302"
)
2024-05-22 15:02:58 +02:00
//go:embed templates/**
var templateFolder embed.FS
2024-05-22 10:42:00 +02:00
func server() {
r := gin.Default()
2024-05-22 15:02:58 +02:00
r.Static("/css", "./cmd/templates/css")
LoadHTMLFromEmbedFS(r, templateFolder, "templates/*.html")
2024-05-22 10:42:00 +02:00
r.GET("/", returnIndex)
2024-05-22 15:02:58 +02:00
r.POST("/api/upload", getCert)
2024-05-22 10:42:00 +02:00
fmt.Printf("Listening on port %v...\n", listenPort)
r.Run(":" + listenPort)
}
func returnIndex(c *gin.Context) {
2024-05-22 15:02:58 +02:00
c.HTML(http.StatusOK, "templates/index.html", gin.H{
2024-05-22 10:42:00 +02:00
"UserAgent": c.Request.UserAgent(),
})
}
2024-05-22 15:02:58 +02:00
func getCert(c *gin.Context) {
text, _ := c.GetPostForm("domain")
fmt.Println(text)
}