Documentation
¶
Index ¶
- Variables
- func FromJSON(i interface{}, r io.Reader) error
- func ToJSON(i interface{}, w io.Writer) error
- type SegmentifyDB
- func (s *SegmentifyDB) Add(ctx context.Context, segment models.CreateSegmentRequest) error
- func (s *SegmentifyDB) ChangeUserSegments(ctx context.Context, us models.UserSegmentsRequest) error
- func (s *SegmentifyDB) Delete(ctx context.Context, slug string) error
- func (s *SegmentifyDB) GetSegmentBySlug(ctx context.Context, slug string) (models.Segment, error)
- func (s *SegmentifyDB) GetSegments(ctx context.Context) (models.Segments, error)
- func (s *SegmentifyDB) GetUserHistory(ctx context.Context, userID int, from, to time.Time) (filename string, err error)
- func (s *SegmentifyDB) GetUsersSegments(ctx context.Context, userID int) (models.ActiveSegments, error)
- type Validation
- type ValidationError
- type ValidationErrors
Constants ¶
This section is empty.
Variables ¶
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 ¶
Types ¶
type SegmentifyDB ¶
type SegmentifyDB struct {
// contains filtered or unexported fields
}
SegmentifyDB is a service that works with segments in the database
func New ¶
func New(l *log.Logger, db *db.PostgresWrapper) *SegmentifyDB
New creates a new SegmentifyDB service
func (*SegmentifyDB) Add ¶
func (s *SegmentifyDB) Add(ctx context.Context, segment models.CreateSegmentRequest) error
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 ¶
GetSegmentBySlug returns a segment from the database by slug
func (*SegmentifyDB) GetSegments ¶
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 (*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