-
Notifications
You must be signed in to change notification settings - Fork 0
/
docslogic.go
44 lines (38 loc) · 876 Bytes
/
docslogic.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package logic
import (
"bytes"
"context"
"encoding/json"
"github.com/tal-tech/go-zero/core/logx"
"github.com/weblfe/bitmap_service/api/internal/svc"
"io/ioutil"
)
type GetIndexLogic struct {
Logger logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewGetIndexLogic(ctx context.Context, svcCtx *svc.ServiceContext) GetIndexLogic {
return GetIndexLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *GetIndexLogic)GetIndex() (map[string]interface{}, error) {
var (
err error
content []byte
decoder *json.Decoder
docs map[string]interface{}
)
content,err = ioutil.ReadFile(l.svcCtx.Config.DocsPath)
if svc.AssertError(err) {
return nil, err
}
decoder = json.NewDecoder(bytes.NewBuffer(content))
if err=decoder.Decode(&docs);svc.AssertError(err) {
return nil,err
}
return docs,nil
}