From ffad456a29844360c0b3af1182ec60a37399ec48 Mon Sep 17 00:00:00 2001 From: raul Date: Wed, 22 May 2024 15:02:58 +0200 Subject: [PATCH] Server improvements --- cmd/server.go | 32 ++++++++++++++++++++++++++++++++ cmd/serverFunc.go | 21 ++++++++++++++------- 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/cmd/server.go b/cmd/server.go index 6eafbdb..041227a 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -35,4 +35,36 @@ func init() { // Cobra supports local flags which will only run when this command // is called directly, e.g.: // 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 } diff --git a/cmd/serverFunc.go b/cmd/serverFunc.go index 634737d..b929185 100644 --- a/cmd/serverFunc.go +++ b/cmd/serverFunc.go @@ -3,29 +3,36 @@ package cmd import ( "embed" "fmt" - "net/http" - - //"github.com/gin-contrib/static" "github.com/gin-gonic/gin" + "net/http" ) var ( listenPort = "1302" ) -//go:embed templates/* -var templatesFolder embed.FS +//go:embed templates/** +var templateFolder embed.FS func server() { 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.POST("/api/upload", getCert) + fmt.Printf("Listening on port %v...\n", listenPort) r.Run(":" + listenPort) } 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(), }) } + +func getCert(c *gin.Context) { + text, _ := c.GetPostForm("domain") + fmt.Println(text) +}