Server improvements

This commit is contained in:
raul 2024-05-22 15:02:58 +02:00
parent e209f85cb0
commit ffad456a29
2 changed files with 46 additions and 7 deletions

View File

@ -35,4 +35,36 @@ func init() {
// Cobra supports local flags which will only run when this command // Cobra supports local flags which will only run when this command
// is called directly, e.g.: // is called directly, e.g.:
// serverCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") // serverCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
serverCmd.Flags().StringP("cert", "c", "$HOME/.config/cert400/server.crt", "CA certificate")
serverCmd.Flags().StringP("key", "k", "$HOME/.config/cert400/server.key", "CA private key")
}
func setServerParams(cmd *cobra.Command) error {
// Get "-f" flag parameters and configure them if not empty
// parameterFile, err := cmd.Flags().GetString("file")
// if err != nil {
// return err
// }
// if parameterFile != "" {
// playIndividualFile = true
// filePath = parameterFile
// }
//
// // Get "-d" flag parameters and configure them if not empty
// parameterDir, err := cmd.Flags().GetString("directory")
// if err != nil {
// return err
// }
// if parameterDir != "" {
// recurseFolders = true
// folderPath = parameterDir
// }
//
// debugParameter, err := cmd.Flags().GetBool("debug")
// if err != nil {
// return err
// }
// if debugParameter == true {
// debuggingMode = true
// }
return nil
} }

View File

@ -3,29 +3,36 @@ package cmd
import ( import (
"embed" "embed"
"fmt" "fmt"
"net/http"
//"github.com/gin-contrib/static"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"net/http"
) )
var ( var (
listenPort = "1302" listenPort = "1302"
) )
//go:embed templates/* //go:embed templates/**
var templatesFolder embed.FS var templateFolder embed.FS
func server() { func server() {
r := gin.Default() r := gin.Default()
//r.Use(static.Serve("/", static.EmbedFolder(templatesFolder, "templates"))) r.Static("/css", "./cmd/templates/css")
LoadHTMLFromEmbedFS(r, templateFolder, "templates/*.html")
r.GET("/", returnIndex) r.GET("/", returnIndex)
r.POST("/api/upload", getCert)
fmt.Printf("Listening on port %v...\n", listenPort) fmt.Printf("Listening on port %v...\n", listenPort)
r.Run(":" + listenPort) r.Run(":" + listenPort)
} }
func returnIndex(c *gin.Context) { func returnIndex(c *gin.Context) {
c.HTML(http.StatusOK, templatesFolder, gin.H{ c.HTML(http.StatusOK, "templates/index.html", gin.H{
"UserAgent": c.Request.UserAgent(), "UserAgent": c.Request.UserAgent(),
}) })
} }
func getCert(c *gin.Context) {
text, _ := c.GetPostForm("domain")
fmt.Println(text)
}