server

package
v0.0.0-...-d71c2e5 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2024 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidValue = errors.New("invalid value")

Functions

func New

func New(config Config) *http.Server

New creates and runs an HTTP server instance for fetching analytics data that can be used later by other third party sites or bots.

Requires 3 parameter that should be sent from the main goroutine.

Types

type Config

type Config struct {
	DB               *sqlx.DB
	Mongo            *mongo.Client
	MongoDBName      string
	Memory           *bigcache.BigCache
	Environment      string
	ListeningAddress string
}

Config is the configuration struct for the server package. Only the Port field is optional. It will be set to 8080 if not set.

type Dependency

type Dependency struct {
	DB          *sqlx.DB
	Memory      *bigcache.BigCache
	Mongo       *mongo.Client
	MongoDBName string
}

Dependency specifies the dependency injection struct for the server package to use.

func (*Dependency) GetAll

func (d *Dependency) GetAll(ctx context.Context) ([]byte, error)

GetAll fetch the users' data either it's from the in memory cache or from the database (if the data does not exist on the memory cache).

func (*Dependency) GetDukunPoints

func (d *Dependency) GetDukunPoints(ctx context.Context) ([]byte, error)

func (*Dependency) GetHourly

func (d *Dependency) GetHourly(ctx context.Context) ([]byte, error)

GetHourly returns hourly message count, specified in a daily kind of object. The data is fetched from the memory cache or the database, if the memory cache data is empty or non-existent.

func (*Dependency) GetTotal

func (d *Dependency) GetTotal(ctx context.Context) ([]byte, error)

GetTotal returns the total amount of chat as the data have it. The data is fetched from the memory cache or the database, if the memory cache data is empty or non-existent.

func (*Dependency) LastUpdated

func (d *Dependency) LastUpdated(r Endpoint) (time.Time, error)

LastUpdated returns the last updated value as a time.Time object for cached data.

type Endpoint

type Endpoint int

Endpoint specifies a type to be used as enum.

const (
	// UserEndpoint indicates the endpoint for getting users data
	UserEndpoint Endpoint = iota
	// HourlyEndpoint indicates the endpoint for getting the data per hour
	HourlyEndpoint
	// TotalEndpoint indicates the endpoint for getting the total amount
	// of messages that was sent per the database's data.
	TotalEndpoint
	// DukunEndpoint indicates the endpoint for getting the whole
	// dukun points as used by the Javascript bot.
	DukunEndpoint
)

type Hourly

type Hourly = analytics.HourlyMap

Hourly is a type alias for analytics.HourlyMap

type User

type User = analytics.GroupMember

User is a type alias for analytics.GroupMember and should be similar for the behavior and other stuffs.

Jump to

Keyboard shortcuts

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