data

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrSegmentNotFound is an error returned when a segment can not be found in the database
	ErrSegmentNotFound = fmt.Errorf("segment not found")

	// ErrSegmentDeleted is an error returned when requested segment was marked as deleted
	ErrSegmentDeleted = fmt.Errorf("segment deleted")

	// ErrSegmentAlreadyExists is an error returned when a segment already exists in the database
	ErrSegmentAlreadyExists = fmt.Errorf("segment already exists")

	// ErrIncorrectChangeUserSegmentsRequest is an error returned when a request to change user segments is incorrect
	ErrIncorrectChangeUserSegmentsRequest = fmt.Errorf("incorrect change user segments request")

	// ErrNoUserData is an error returned when there is no user data about segments for given userID
	ErrNoUserData = fmt.Errorf("no user data about segments for given userID")

	// ErrNoUserHistoryData is an error returned when there is no user history data about segments for given userID
	// for specified period.
	ErrNoUserHistoryData = fmt.Errorf("no user history data about segments for given userID")
)

Functions

func FromJSON

func FromJSON(i interface{}, r io.Reader) error

FromJSON deserializes the object from JSON string in an io.Reader to the given interface

func ToJSON

func ToJSON(i interface{}, w io.Writer) error

ToJSON serializes the given interface into a string based JSON format

Types

type SegmentifyDB

type SegmentifyDB struct {
	// contains filtered or unexported fields
}

SegmentifyDB is a service that works with segments in the database

func New

New creates a new SegmentifyDB service

func (*SegmentifyDB) Add

Add adds a new segment to the database

func (*SegmentifyDB) ChangeUserSegments

func (s *SegmentifyDB) ChangeUserSegments(ctx context.Context, us models.UserSegmentsRequest) error

ChangeUserSegments changes user's segments

func (*SegmentifyDB) Delete

func (s *SegmentifyDB) Delete(ctx context.Context, slug string) error

Delete deletes a segment from the database

func (*SegmentifyDB) GetSegmentBySlug

func (s *SegmentifyDB) GetSegmentBySlug(ctx context.Context, slug string) (models.Segment, error)

GetSegmentBySlug returns a segment from the database by slug

func (*SegmentifyDB) GetSegments

func (s *SegmentifyDB) GetSegments(ctx context.Context) (models.Segments, error)

GetSegments returns all segments from the database

func (*SegmentifyDB) GetUserHistory

func (s *SegmentifyDB) GetUserHistory(ctx context.Context, userID int, from, to time.Time) (filename string, err error)

GetUserHistory returns user's segments history

func (*SegmentifyDB) GetUsersSegments

func (s *SegmentifyDB) GetUsersSegments(ctx context.Context, userID int) (models.ActiveSegments, error)

GetUsersSegments returns user's segments

type Validation

type Validation struct {
	// contains filtered or unexported fields
}

Validation wraps the go-playground/validator

func NewValidation

func NewValidation() *Validation

NewValidation creates a new Validation type

func (*Validation) Validate

func (v *Validation) Validate(i interface{}) ValidationErrors

Validate the item for more detail the returned error can be cast into a validator.ValidationErrors collection

if ve, ok := err.(validator.ValidationErrors); ok {
			fmt.Println(ve.Namespace())
			fmt.Println(ve.Field())
			fmt.Println(ve.StructNamespace())
			fmt.Println(ve.StructField())
			fmt.Println(ve.Tag())
			fmt.Println(ve.ActualTag())
			fmt.Println(ve.Kind())
			fmt.Println(ve.Type())
			fmt.Println(ve.Value())
			fmt.Println(ve.Param())
			fmt.Println()
	}

type ValidationError

type ValidationError struct {
	validator.FieldError
}

ValidationError wraps the validators FieldError, so we do not expose this to out code

func (ValidationError) Error

func (v ValidationError) Error() string

Error returns the validation error message

type ValidationErrors

type ValidationErrors []ValidationError

ValidationErrors is a collection of ValidationError

func (ValidationErrors) Errors

func (v ValidationErrors) Errors() []string

Errors converts the slice into a string slice

Jump to

Keyboard shortcuts

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