36 lines
706 B
Go
36 lines
706 B
Go
|
|
package hello
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
|
||
|
|
"github.com/gin-contrib/sessions"
|
||
|
|
"github.com/gin-gonic/gin"
|
||
|
|
)
|
||
|
|
|
||
|
|
// Ping
|
||
|
|
func Ping(ctx *gin.Context) {
|
||
|
|
|
||
|
|
// file, err := ctx.FormFile("fileContent")
|
||
|
|
// if err != nil {
|
||
|
|
// fmt.Println("err", err)
|
||
|
|
// return
|
||
|
|
// }
|
||
|
|
|
||
|
|
// ctx.SaveUploadedFile(file, "./tmp/"+file.Filename)
|
||
|
|
// ctx.JSON(200, gin.H{
|
||
|
|
// "msg": file,
|
||
|
|
// })
|
||
|
|
ctx.JSON(200, gin.H{"message": "Pong"})
|
||
|
|
}
|
||
|
|
func SessionDemo(ctx *gin.Context) {
|
||
|
|
session := sessions.Default(ctx)
|
||
|
|
session.Set("key", "12345")
|
||
|
|
if err := session.Save(); err != nil {
|
||
|
|
ctx.JSON(500, gin.H{"error": err.Error()})
|
||
|
|
return
|
||
|
|
}
|
||
|
|
value := session.Get("key")
|
||
|
|
fmt.Println("session value: ", value)
|
||
|
|
ctx.JSON(200, gin.H{"message": "Pong"})
|
||
|
|
}
|