summaryrefslogblamecommitdiff
path: root/pkg/idec/idec.go
blob: d50c2004074b70bfc846582a3fba2dee5eb1c078 (plain) (tree)





















                                                                                   
                                




























                                                       
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"
	blacklist = "_blacklist"
)

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
}