Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
search_server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
9d7afea4
authored
Oct 22, 2020
by
huangchengyi
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
1.0
parent
2e834757
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
8 additions
and
9 deletions
cmd/http/http
middleware/cors.go
pkg/common/response.go
pkg/mongo/mongo.go
cmd/http/http
View file @
9d7afea4
The file could not be displayed because it is too large.
middleware/cors.go
View file @
9d7afea4
...
...
@@ -8,11 +8,12 @@ import (
)
func
Cors
()
gin
.
HandlerFunc
{
corsDomain
:=
config
.
Get
(
"web.cors_domain"
)
.
Strings
(
","
)
corsDomain
=
append
(
corsDomain
,
"https://bom.ichunt.com"
)
corsDomain
=
append
(
corsDomain
,
"https://bom.ichunt.com"
)
return
cors
.
New
(
cors
.
Config
{
AllowOrigins
:
corsDomain
,
AllowHeaders
:
[]
string
{
"x-requested-with"
,
"Authorization"
,
"Content-Type"
},
AllowMethods
:
[]
string
{
"POST"
,
"GET"
,
"PUT"
,
"DELETE"
},
AllowCredentials
:
true
,
MaxAge
:
12
*
time
.
Hour
,
...
...
pkg/common/response.go
View file @
9d7afea4
...
...
@@ -5,7 +5,6 @@ import (
"github.com/gin-gonic/gin"
"runtime"
"strconv"
"strings"
)
type
Response
struct
{
...
...
@@ -54,10 +53,10 @@ func Output(ctx *gin.Context,errCode int, errMsg string, data interface{}) {
if
ctx
.
DefaultQuery
(
"callback"
,
""
)
!=
""
{
ctx
.
JSONP
(
200
,
response
)
}
else
{
referer
:=
ctx
.
Request
.
Referer
()
referer
=
strings
.
TrimRight
(
referer
,
"/"
)
ctx
.
Header
(
"Access-Control-Allow-Origin"
,
referer
)
ctx
.
Header
(
"Access-Control-Allow-Credentials"
,
"true"
)
//
referer := ctx.Request.Referer()
//
referer = strings.TrimRight(referer, "/")
//
ctx.Header("Access-Control-Allow-Origin", referer)
//
ctx.Header("Access-Control-Allow-Credentials", "true")
//允许跨站访问的站点域名
//跨域请求头设置
ctx
.
JSON
(
200
,
response
)
...
...
pkg/mongo/mongo.go
View file @
9d7afea4
package
mongo
import
(
"fmt"
"gopkg.in/mgo.v2"
"search_server/pkg/config"
"strconv"
...
...
@@ -30,8 +29,8 @@ func getconn(mongoConfig config.MongoDbDatabase) (*mgo.Session ,error){
if
err
!=
nil
{
return
nil
,
err
}
fmt
.
Println
(
"url"
,
url
)
fmt
.
Println
(
"maxPoolSizeInt"
,
maxPoolSizeInt
)
//
fmt.Println("url",url)
//
fmt.Println("maxPoolSizeInt",maxPoolSizeInt)
session
.
SetPoolLimit
(
maxPoolSizeInt
)
session
.
SetMode
(
mgo
.
Monotonic
,
true
)
myDB
:=
session
.
DB
(
mongoConfig
.
Database
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment