summaryrefslogtreecommitdiff
path: root/pkg/idec/idec.go
blob: 0692d656d1bb64cb1f79834cf6d9a666647f4312 (plain) (blame)
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
44
45
46
47
48
49
50
51
package idec

import (
	"errors"

	"gitrepo.ru/neonxp/idecnode/pkg/config"
	"go.etcd.io/bbolt"
)

var Features = []string{"list.txt", "blacklist.txt", "u/e", "u/m", "x/c", "m", "e"}

var (
	ErrUserNotFound       = errors.New("user not found")
	ErrMessageNotFound    = errors.New("message not found")
	ErrFailedSaveMessage  = errors.New("- failed save message")
	ErrWrongMessageFormat = errors.New("- wrong message format")
	ErrNoAuth             = errors.New("no auth - wrong authstring")
)

const (
	msgBucket = "_msg"
	points    = "_points"
)

type IDEC struct {
	config *config.Config
	db     *bbolt.DB
}

func New(config *config.Config) (*IDEC, error) {
	db, err := bbolt.Open(config.Store, 0o600, nil)
	if err != nil {
		return nil, err
	}

	return &IDEC{
		config: config,
		db:     db,
	}, nil
}

func (i *IDEC) Close() error {
	return i.db.Close()
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}