parent
8d95f7a947
commit
3a50ec0463
@ -1,54 +0,0 @@
|
||||
package pconline
|
||||
|
||||
import (
|
||||
"go.dtapp.net/library/utils/golog"
|
||||
"go.dtapp.net/library/utils/gomongo"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
mongo *gomongo.Client // 日志数据库
|
||||
pgsql *gorm.DB // pgsql数据库
|
||||
client *gorequest.App // 请求客户端
|
||||
log *golog.Api // 日志服务
|
||||
logTableName string // 日志表名
|
||||
logStatus bool // 日志状态
|
||||
}
|
||||
|
||||
func NewApp(pgsql *gorm.DB) *App {
|
||||
app := &App{}
|
||||
app.client = gorequest.NewHttp()
|
||||
if pgsql != nil {
|
||||
app.pgsql = pgsql
|
||||
app.logStatus = true
|
||||
app.logTableName = "pconline"
|
||||
app.log = golog.NewClientApi(pgsql, app.logTableName)
|
||||
}
|
||||
return app
|
||||
}
|
||||
|
||||
func (app *App) request(url string) (resp gorequest.Response, err error) {
|
||||
|
||||
// 创建请求
|
||||
client := app.client
|
||||
|
||||
// 设置请求地址
|
||||
client.SetUri(url)
|
||||
|
||||
// 发起请求
|
||||
request, err := client.Get()
|
||||
if err != nil {
|
||||
return gorequest.Response{}, err
|
||||
}
|
||||
|
||||
// 日志
|
||||
if app.mongo != nil && app.mongo.Db != nil {
|
||||
go app.mongoLog(request)
|
||||
}
|
||||
if app.logStatus == true {
|
||||
go app.postgresqlLog(request)
|
||||
}
|
||||
|
||||
return request, err
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package pconline
|
||||
|
||||
import (
|
||||
"go.dtapp.net/library/utils/golog"
|
||||
"go.dtapp.net/library/utils/gomongo"
|
||||
"go.dtapp.net/library/utils/gorequest"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ConfigClient struct {
|
||||
MongoDb *gomongo.Client // 日志数据库
|
||||
PgsqlDb *gorm.DB // pgsql数据库
|
||||
}
|
||||
|
||||
type Client struct {
|
||||
client *gorequest.App // 请求客户端
|
||||
log *golog.ApiClient // 日志服务
|
||||
logStatus bool // 日志状态
|
||||
config *ConfigClient // 配置
|
||||
}
|
||||
|
||||
func NewClient(config *ConfigClient) (*Client, error) {
|
||||
|
||||
var err error
|
||||
c := &Client{config: config}
|
||||
|
||||
c.client = gorequest.NewHttp()
|
||||
if c.config.PgsqlDb != nil {
|
||||
c.logStatus = true
|
||||
c.log, err = golog.NewApiClient(&golog.ConfigApiClient{
|
||||
Db: c.config.PgsqlDb,
|
||||
TableName: logTable,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return c, nil
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package pconline
|
||||
|
||||
const (
|
||||
apiUrl = "https://whois.pconline.com.cn"
|
||||
)
|
||||
|
||||
const (
|
||||
logTable = "pconline"
|
||||
)
|
@ -0,0 +1,28 @@
|
||||
package pconline
|
||||
|
||||
import "go.dtapp.net/library/utils/gorequest"
|
||||
|
||||
func (c *Client) request(url string) (gorequest.Response, error) {
|
||||
|
||||
// 创建请求
|
||||
client := c.client
|
||||
|
||||
// 设置请求地址
|
||||
client.SetUri(url)
|
||||
|
||||
// 发起请求
|
||||
request, err := client.Get()
|
||||
if err != nil {
|
||||
return gorequest.Response{}, err
|
||||
}
|
||||
|
||||
// 日志
|
||||
if c.config.MongoDb != nil {
|
||||
go c.mongoLog(request)
|
||||
}
|
||||
if c.logStatus == true {
|
||||
go c.postgresqlLog(request)
|
||||
}
|
||||
|
||||
return request, err
|
||||
}
|
Loading…
Reference in new issue