41 lines
918 B
Go
41 lines
918 B
Go
package controllers
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
|
|
"github.com/NothAmor/SourceTraceFront/common"
|
|
"github.com/NothAmor/SourceTraceFront/models"
|
|
"github.com/NothAmor/SourceTraceFront/proto"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func Myself(c *gin.Context) {
|
|
var listUsers []models.Users
|
|
pageArgs := proto.PageArgs{Page: 1}
|
|
err := common.RPC.Call(context.Background(), "ListUsers", pageArgs, &listUsers)
|
|
if err != nil {
|
|
log.Printf("failed to call: %v", err)
|
|
return
|
|
}
|
|
if len(listUsers) == 0 {
|
|
c.HTML(http.StatusOK, "myself.html", gin.H{
|
|
"name": "未登录",
|
|
})
|
|
return
|
|
}
|
|
userInfo := listUsers[0]
|
|
fmt.Printf("userInfo:%v\n", userInfo)
|
|
c.HTML(http.StatusOK, "myself.html", gin.H{
|
|
"id": userInfo.ID,
|
|
"name": userInfo.Name,
|
|
"gender": userInfo.Gender,
|
|
"avatar": userInfo.Avatar,
|
|
"address": userInfo.Address,
|
|
"email": userInfo.Email,
|
|
"phone": userInfo.Phone,
|
|
})
|
|
}
|