aboutsummaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorveradec <glitchmill.dyj3d@simplelogin.co>2026-11-11 13:14:08 +0530
committerveradec <glitchmill.dyj3d@simplelogin.co>2026-11-11 13:14:08 +0530
commitad2f596828f6f66e5c06be64497fab56b085dff5 (patch)
treed59f5ab0119da586a6c7e87fe8c5ca2845e6424e /main.go
init: basic file uploading works
Diffstat (limited to 'main.go')
-rw-r--r--main.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..4e528df
--- /dev/null
+++ b/main.go
@@ -0,0 +1,31 @@
+package main
+
+import (
+ "net/http"
+ "fmt"
+ "path/filepath"
+ "github.com/gin-gonic/gin"
+)
+
+func index(c *gin.Context){
+
+}
+
+func main(){
+ router := gin.Default()
+
+ router.POST("/", func(c *gin.Context) {
+ // single file
+ file, err := c.FormFile("file")
+ if err != nil {
+ c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
+ return
+ }
+ fmt.Println(file.Filename)
+
+ dst := filepath.Join("./files/", filepath.Base(file.Filename))
+ c.SaveUploadedFile(file, dst)
+ c.String(http.StatusOK, fmt.Sprintf("'%s' uploaded!\n", file.Filename))
+ })
+ router.Run(":8080")
+}