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
a073bfbf
authored
Jun 08, 2020
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
整合商品请求
parent
abab2f4d
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
5 deletions
conf/config.ini
readme.md
service/goods_service.go
test/test.go
conf/config.ini
View file @
a073bfbf
...
...
@@ -5,6 +5,9 @@ port = 9000
api_domain
=
http://api.ichunt.com/msg/sendMessageByAuto
api_md5_str
=
fh6y5t4rr351d2c3bryi
[goods]
api_url
=
http://192.168.2.232:60004
[database]
user_name
=
root
password
=
root
...
...
readme.md
View file @
a073bfbf
## 搜索服务
### 项目启动
直接到cmd下面
直接到cmd下面直接找到想启动的服务进行
```go run xxx```
即可,需要传入配置文件地址的话,则可以
```
go run xxx.go -config xxx/xxx.ini```
### 目录结构
├── bat //运行脚本或者protoc生成脚本
├── boot //启动文件,比如配置加载,数据库加载等等
...
...
@@ -16,14 +19,18 @@
├── service //业务逻辑操作所在目录
### 已经封装的模块以及用法
#### 1.配置读取
接在```conf/config.ini```文件添加自己的配置项
然后使用
```config.Get("xxx.xxx")```
即可
然后使用```config.Get("xxx.xxx")
.String()```或者```config.Get("xxx.xxx").Int()
```即可
#### 2.mysql连接实例
使用```mysql.GetDB()```即可获取对应的实例,不同数据库的连接可以自己定义不同的GetDB方法
#### 3.redis使用
可以直接调用```gredis.Hset(),gredis.Hget()```等方法,具体使用请参考代码,其中返回的结果是一个redis对象,需要自己转成自己需要的类型
```
redis.String(gredis.HGet("test",1))
```
#### 4.mgo连接实例
使用```
mongo.GetDB()
```即可,不同数据库的连接可以自己定义不同的GetDB方法
然后用C方法指定集合进行操作即可:
...
...
service/goods_service.go
0 → 100644
View file @
a073bfbf
package
service
import
(
"github.com/imroc/req"
"search_server/pkg/config"
)
//商品服务请求,传入的是goods_id的字符串,可以是单个id,也可以是多个id用逗号隔开
func
GetGoodsInfo
(
goodsIdsStr
string
)
(
result
string
)
{
goodsServerUrl
:=
config
.
Get
(
"goods.api_url"
)
.
String
()
params
:=
req
.
Param
{
"goods_id"
:
goodsIdsStr
,
}
resp
,
err
:=
req
.
Post
(
goodsServerUrl
+
"/synchronization"
,
params
)
if
err
!=
nil
{
return
}
return
resp
.
String
()
}
test/test.go
View file @
a073bfbf
...
...
@@ -4,7 +4,6 @@ import (
"flag"
"log"
"search_server/boot"
"search_server/pkg/message"
)
func
main
()
{
...
...
@@ -14,6 +13,4 @@ func main() {
if
err
:=
boot
.
Boot
(
path
);
err
!=
nil
{
log
.
Println
(
err
)
}
message
.
SendMessage
(
18825159814
,
"es_connect_monitor"
,
map
[
string
]
interface
{}{
"ip"
:
"127.0.0.1"
})
}
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