@@ -0,0 +1,13 @@
+package admin
+
+import (
+ . "jy/router"
+)
+func init() {
+ admin := Router.Group("/admin")
+ admin.Use(AuthMiddleWare())
+ {
+ admin.Static("/web", "./web/admin")
+ }
+}
@@ -12,7 +12,7 @@ import (
func init() {
//登录
- Router.POST("/login", func(c *gin.Context) {
+ Router.GET("/login", func(c *gin.Context) {
name := c.GetString("name")
pwd := c.GetString("pwd")
res, b := Mgo.FindOne("user", fmt.Sprintf(`{"name":"%s","pwd":"%s"}`, name, pwd))
@@ -1,6 +1,8 @@
package router
import (
+ "net/http"
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/memstore"
"github.com/gin-gonic/gin"
@@ -11,5 +13,19 @@ var Router = gin.Default()
store := memstore.NewStore([]byte("jy_data_extract"))
Router.Use(sessions.Sessions("mysession", store))
- Router.Run(":9090")
+func AuthMiddleWare() gin.HandlerFunc {
+ return func(c *gin.Context) {
+ session := sessions.Default(c)
+ if session.Get("name") != nil {
+ c.Next()
+ return
+ c.JSON(http.StatusUnauthorized, gin.H{
+ "error": "Unauthorized",
+ })
+ c.Abort()
}
@@ -1,14 +1,16 @@
package main
- "jy/front"
+ _ "jy/admin"
+ _ "jy/front"
_ "jy/mongodbutil"
"log"
"time"
)
func main() {
- go front.Server()
- log.Println("启动..")
+ go Router.Run(":9090")
+ go log.Println("启动..")
time.Sleep(99999 * time.Hour)
@@ -0,0 +1,14 @@
+<!doctype html>
+<html lang="en">
+ <head>
+ <meta charset="UTF-8">
+ <meta name="Generator" content="EditPlus®">
+ <meta name="Author" content="">
+ <meta name="Keywords" content="">
+ <meta name="Description" content="">
+ <title>Document</title>
+ </head>
+ <body>
+ aaaaaaaaaaaaaaaaa
+ </body>
+</html>