diff --git a/go.mod b/go.mod index 291de40..05836d3 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/IceWhaleTech/CasaOS-UserService go 1.18 require ( - github.com/IceWhaleTech/CasaOS-Common v0.0.0-20220811230555-229797f76426 + github.com/IceWhaleTech/CasaOS-Common v0.0.0-20220825191226-4519f1880f68 github.com/IceWhaleTech/CasaOS-Gateway v0.0.0-20220804231126-285796241a3b github.com/gin-contrib/gzip v0.0.6 github.com/gin-gonic/gin v1.8.1 diff --git a/go.sum b/go.sum index 3701484..9c54ed1 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,6 @@ github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0= -github.com/IceWhaleTech/CasaOS-Common v0.0.0-20220811230555-229797f76426 h1:+Yc9qJ6AehudNsIRkoyTe8dmHiHDWsPF/QL7qk8Va6o= -github.com/IceWhaleTech/CasaOS-Common v0.0.0-20220811230555-229797f76426/go.mod h1:XGqdbedN9UlF3/rylcXKJ2BW4ayugBmEMa4Z0tk2KbQ= +github.com/IceWhaleTech/CasaOS-Common v0.0.0-20220825191226-4519f1880f68 h1:KMFS0/08mKgZqsM8fd5If/1NOLwtIvi7dljFEkJCdSw= +github.com/IceWhaleTech/CasaOS-Common v0.0.0-20220825191226-4519f1880f68/go.mod h1:XGqdbedN9UlF3/rylcXKJ2BW4ayugBmEMa4Z0tk2KbQ= github.com/IceWhaleTech/CasaOS-Gateway v0.0.0-20220804231126-285796241a3b h1:IiMCqvGelQLGTX151gqVwrzoPQVJy8Q2JAvkhjiQ6tY= github.com/IceWhaleTech/CasaOS-Gateway v0.0.0-20220804231126-285796241a3b/go.mod h1:jcURlZtPPQJJvfIW4ZgDTtpFfak7bPTvKZUxWxf62M8= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= diff --git a/main.go b/main.go index 1ef7fa1..e6f68b0 100644 --- a/main.go +++ b/main.go @@ -3,7 +3,6 @@ package main import ( "flag" "fmt" - "log" "net" "net/http" "os" @@ -16,6 +15,7 @@ import ( "github.com/IceWhaleTech/CasaOS-UserService/pkg/utils/random" "github.com/IceWhaleTech/CasaOS-UserService/route" "github.com/IceWhaleTech/CasaOS-UserService/service" + "go.uber.org/zap" ) const ( @@ -87,7 +87,7 @@ func main() { panic(err) } - log.Printf("user service listening on %s", listener.Addr().String()) + logger.Info("User service is listening...", zap.Any("address", listener.Addr().String())) err = http.Serve(listener, r) if err != nil { panic(err) diff --git a/middleware/gin.go b/middleware/gin.go deleted file mode 100644 index c273808..0000000 --- a/middleware/gin.go +++ /dev/null @@ -1,61 +0,0 @@ -/* - * @Author: LinkLeong link@icewhale.com - * @Date: 2021-10-08 10:29:08 - * @LastEditors: LinkLeong - * @LastEditTime: 2022-07-22 11:06:07 - * @Description: - * @Website: https://www.casaos.io - * Copyright (c) 2022 by icewhale, All Rights Reserved. - */ -package middleware - -import ( - "fmt" - "net/http" - "strings" - - "github.com/IceWhaleTech/CasaOS-Common/utils/logger" - "github.com/gin-gonic/gin" - "go.uber.org/zap" -) - -func Cors() gin.HandlerFunc { - return func(c *gin.Context) { - method := c.Request.Method - - c.Header("Access-Control-Allow-Origin", "*") - c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE,UPDATE") - // 允许跨域设置可以返回其他子段,可以自定义字段 - c.Header("Access-Control-Allow-Headers", "Authorization, Content-Length, X-CSRF-Token, Token,session,Language,Content-Type,Access-Control-Allow-Origin,Access-Control-Allow-Headers,Access-Control-Allow-Methods,Connection,Host,Origin,Referer,User-Agent,X-Requested-With") - // 允许浏览器(客户端)可以解析的头部 (重要) - c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers") - // c.Writer.Header().Set("Access-Control-Allow-Headers", "Accept, Authorization, Content-Type, Content-Length, X-CSRF-Token, Token, session, Origin, Host, Connection, Accept-Encoding, Accept-Language, X-Requested-With") - // 设置缓存时间 - c.Header("Access-Control-Max-Age", "172800") - c.Header("Access-Control-Allow-Credentials", "true") - c.Set("Content-Type", "application/json") - //} - - // 允许类型校验 - if method == "OPTIONS" { - c.JSON(http.StatusOK, "ok!") - } - - defer func() { - if err := recover(); err != nil { - fmt.Println(err) - } - }() - - c.Next() - } -} - -func WriteLog() gin.HandlerFunc { - return func(c *gin.Context) { - if !strings.Contains(c.Request.URL.String(), "password") { - logger.Info("request:", zap.Any("path", c.Request.URL.String()), zap.Any("param", c.Params), zap.Any("query", c.Request.URL.Query()), zap.Any("method", c.Request.Method)) - c.Next() - } - } -} diff --git a/route/route.go b/route/route.go index a58ed6c..127f67f 100644 --- a/route/route.go +++ b/route/route.go @@ -3,8 +3,8 @@ package route import ( "os" + "github.com/IceWhaleTech/CasaOS-Common/middleware" "github.com/IceWhaleTech/CasaOS-Common/utils/jwt" - "github.com/IceWhaleTech/CasaOS-UserService/middleware" v1 "github.com/IceWhaleTech/CasaOS-UserService/route/v1" "github.com/gin-contrib/gzip" "github.com/gin-gonic/gin"