mirror of
https://github.com/eiblog/eiblog.git
synced 2026-02-10 00:22:27 +08:00
chore: store mongodb
This commit is contained in:
@@ -10,8 +10,8 @@ import (
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/eiblog/eiblog/v2/pkg/config"
|
||||
"github.com/eiblog/eiblog/v2/pkg/model"
|
||||
"github.com/eiblog/eiblog/pkg/config"
|
||||
"github.com/eiblog/eiblog/pkg/model"
|
||||
)
|
||||
|
||||
// disqus api
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/eiblog/eiblog/v2/pkg/config"
|
||||
"github.com/eiblog/eiblog/pkg/config"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
@@ -30,7 +30,7 @@ func init() {
|
||||
}
|
||||
|
||||
mappings := fmt.Sprintf(`{"mappings":{"%s":{"properties":{"content":{"analyzer":"ik_syno","search_analyzer":"ik_syno","term_vector":"with_positions_offsets","type":"string"},"date":{"index":"not_analyzed","type":"date"},"slug":{"type":"string"},"tag":{"index":"not_analyzed","type":"string"},"title":{"analyzer":"ik_syno","search_analyzer":"ik_syno","term_vector":"with_positions_offsets","type":"string"}}}}}`, "article")
|
||||
err := createIndexAndMappings("article", "eiblog", []byte(mappings))
|
||||
err := createIndexAndMappings("eiblog", "article", []byte(mappings))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@@ -130,7 +130,7 @@ func createIndexAndMappings(index, typ string, mappings []byte) error {
|
||||
result := indicesCreateResult{}
|
||||
err = json.Unmarshal(data, &result)
|
||||
if err != nil {
|
||||
return err
|
||||
return errors.New(string(data))
|
||||
}
|
||||
if !result.Acknowledged {
|
||||
return errors.New(string(data))
|
||||
|
||||
@@ -36,16 +36,21 @@ func newRequest(method, rawurl string, data interface{}) (*http.Request, error)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
host := u.Host
|
||||
originHost := u.Host
|
||||
// 获取主机IP
|
||||
ips, err := net.LookupHost(u.Host)
|
||||
host, port, err := net.SplitHostPort(u.Host)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ips, err := net.LookupHost(host)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(ips) == 0 {
|
||||
return nil, fmt.Errorf("http: not found ip(%s)", u.Host)
|
||||
}
|
||||
u.Host = ips[0]
|
||||
host = net.JoinHostPort(ips[0], port)
|
||||
u.Host = host
|
||||
// 创建HTTP Request
|
||||
var req *http.Request
|
||||
switch raw := data.(type) {
|
||||
@@ -65,7 +70,7 @@ func newRequest(method, rawurl string, data interface{}) (*http.Request, error)
|
||||
return nil, err
|
||||
}
|
||||
// 设置Host
|
||||
req.Host = host
|
||||
req.Host = originHost
|
||||
return req, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,8 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/eiblog/eiblog/v2/pkg/config"
|
||||
"github.com/eiblog/eiblog/pkg/config"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"io"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/eiblog/eiblog/v2/pkg/config"
|
||||
"github.com/eiblog/eiblog/pkg/config"
|
||||
|
||||
"github.com/qiniu/api.v7/v7/auth/qbox"
|
||||
"github.com/qiniu/api.v7/v7/storage"
|
||||
|
||||
Reference in New Issue
Block a user