elling

package
v0.0.0-...-0b73d59 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2022 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ResponseJson       ResponseType = "JSON"
	ResponseURLEncoded              = "URLEncoded"
	ResponsePlain                   = "PLAIN"
	ResponseNone                    = "NONE"
)

Variables

View Source
var BillingTypeNotSupportedError = errors.New("specified billing type is not supported by the product")
View Source
var DB *gorm.DB
View Source
var DailyBilling = RegisterBilling("daily", time.Hour*24)
View Source
var HourlyBilling = RegisterBilling("hourly", time.Hour)
View Source
var LocalDispatchers = make(map[reflect.Type][]*Dispatcher)
View Source
var ModuleDispatchers = make(map[reflect.Type][]*Dispatcher)
View Source
var MonthlyBilling = RegisterBilling("monthly", time.Hour*24*30)
View Source
var NotEnoughFundsError = errors.New("not enough funds")
View Source
var OneTimeBilling = RegisterBilling("onetime", 0)
View Source
var PathNotFoundError = errors.New("url decoding path not found")
View Source
var QuarterlyBilling = RegisterBilling("quarterly", time.Hour*24*90)
View Source
var Redis *redis.Conn
View Source
var WeeklyBilling = RegisterBilling("weekly", time.Hour*24*7)
View Source
var YearlyBilling = RegisterBilling("yearly", time.Hour*24*365)

Functions

func CloseDatabase

func CloseDatabase()

func DispatchEvent

func DispatchEvent(event interface{})

func DoBigTick

func DoBigTick()

func DoSmallTick

func DoSmallTick()

func InitID

func InitID()

func LoadDatabase

func LoadDatabase()

func NextID

func NextID() uint64

func RegisterListener

func RegisterListener(d interface{})

func RegisterProduct

func RegisterProduct(meta *ProductMeta)

Types

type Balance

type Balance struct {
	ID     uint64 `json:"id,omitempty"`
	Amount int64  `json:"amount"`
}

func NewBalance

func NewBalance() (*Balance, error)

func (*Balance) Deposit

func (b *Balance) Deposit(delta int64) error

func (*Balance) Update

func (b *Balance) Update() error

func (*Balance) Withdraw

func (b *Balance) Withdraw(delta int64) error

type BalanceChangeEvent

type BalanceChangeEvent struct {
	Balance *Balance
	Delta   int64
}

type BigTickEvent

type BigTickEvent struct{}

type Billing

type Billing struct {
	Name     string
	Duration time.Duration
}

func GetBilling

func GetBilling(name string) *Billing

func RegisterBilling

func RegisterBilling(name string, duration time.Duration) *Billing

type DBModel

type DBModel struct {
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt `gorm:"index"`
}

type Dispatcher

type Dispatcher struct {
	Method reflect.Value
}

func (*Dispatcher) Dispatch

func (d *Dispatcher) Dispatch(event interface{})

type Logger

type Logger struct{}

func (*Logger) Error

func (l *Logger) Error(_ context.Context, msg string, data ...interface{})

func (*Logger) Info

func (l *Logger) Info(_ context.Context, msg string, data ...interface{})

func (*Logger) LogMode

func (l *Logger) LogMode(_ logger.LogLevel) logger.Interface

func (*Logger) Trace

func (l *Logger) Trace(_ context.Context, begin time.Time, fc func() (string, int64), _ error)

func (*Logger) Warn

func (l *Logger) Warn(_ context.Context, msg string, data ...interface{})

type NetRequest

type NetRequest struct {
	URL               string            `yaml:"url"`
	Method            string            `yaml:"method"`
	Headers           map[string]string `yaml:"headers"`
	Data              string            `yaml:"data"`
	ResponseType      ResponseType      `yaml:"response-type"`
	ResponseValuePath []string          `yaml:"response-value-path"`
}

func (*NetRequest) DoRequest

func (request *NetRequest) DoRequest(replaceValues map[string]string) ([]string, error)

type Product

type Product struct {
	ID            uint64
	DisplayName   string
	Billing       string
	BalanceID     uint64 `json:"-"`
	Module        string
	Type          string
	Users         []*User `gorm:"many2many:user_products;"`
	PaidTill      time.Time
	Suspended     bool
	SuspendReason string
}

func (*Product) ChangeBilling

func (p *Product) ChangeBilling(billing *Billing) error

func (*Product) GetBalance

func (p *Product) GetBalance() (*Balance, error)

func (*Product) GetCost

func (p *Product) GetCost() int64

func (*Product) GetMeta

func (p *Product) GetMeta() *ProductMeta

func (*Product) Prolong

func (p *Product) Prolong(period int64) error

func (*Product) SuspendProduct

func (p *Product) SuspendProduct(reason string) error

func (*Product) UnsuspendProduct

func (p *Product) UnsuspendProduct() error

func (*Product) Update

func (p *Product) Update() error

type ProductDeletedEvent

type ProductDeletedEvent struct {
	Product *Product
}

type ProductListener

type ProductListener struct{}

func (*ProductListener) OnSmallTick

func (*ProductListener) OnSmallTick(_ SmallTickEvent)

type ProductMeta

type ProductMeta struct {
	DisplayName       string
	Name              string
	Type              string
	AvailableBillings map[string]bool
	BillingCost       map[string]int64
}

type ProductOrderedEvent

type ProductOrderedEvent struct {
	Product *Product
}

type ProductSuspendEvent

type ProductSuspendEvent struct {
	Product *Product
	Reason  string
}

type ProductUnsuspendEvent

type ProductUnsuspendEvent struct {
	Product *Product
}

type ResponseType

type ResponseType string

type SmallTickEvent

type SmallTickEvent struct{}

type User

type User struct {
	ID        uint64    `json:"id"`
	BalanceID int64     `json:"-"`
	Balance   Balance   `json:"balance"`
	Products  []Product `json:"products,omitempty" gorm:"many2many:user_products;"`
	Token     string    `json:"token,omitempty"`
	Active    bool      `json:"active"`
}

func NewUser

func NewUser() *User

func (*User) Activate

func (u *User) Activate()

func (*User) AddProduct

func (u *User) AddProduct(displayName, billing, module, typeName string, user User) error

func (*User) Deactivate

func (u *User) Deactivate()

func (*User) FetchProducts

func (u *User) FetchProducts() error

type UserActivationEvent

type UserActivationEvent struct {
	User *User
}

type UserCreationEvent

type UserCreationEvent struct {
	User *User
}

type UserDeactivationEvent

type UserDeactivationEvent struct {
	User *User
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL