model

package
v0.1.0-a6 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2019 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MinUsernameLength constant
	MinUsernameLength = 4
	// MaxUsernameLength constant
	MaxUsernameLength = 100
	// MinPasswordLength constant
	MinPasswordLength = 8
	// MaxPasswordLength constant
	MaxPasswordLength = 100
)
View Source
const (
	// RepositoryTypeGithub constant
	RepositoryTypeGithub = "github"
)
View Source
const (
	// RoleAdmin role key
	RoleAdmin = "admin"
)

Variables

View Source
var AllowedRepositoryTypes = []string{RepositoryTypeGithub}

AllowedRepositoryTypes contains the list of allowed repository types

Functions

func AuthFromJSON

func AuthFromJSON(data io.Reader) (*Auth, *AppError)

AuthFromJSON build a auth body from a JSON body

func CategoryFromJSON

func CategoryFromJSON(data io.Reader) (*Category, *AppError)

CategoryFromJSON build a user from a JSON body

func ComparePassword

func ComparePassword(hash string, password string) bool

ComparePassword compares the hash to a plaintext password

func HashPassword

func HashPassword(password string) (string, error)

HashPassword generates a hash using the bcrypt.GenerateFromPassword

func NewJSONToken

func NewJSONToken(s string) []byte

NewJSONToken return a json body with the jwt token

func RegistrationFromJSON

func RegistrationFromJSON(data io.Reader) (*Registration, *AppError)

RegistrationFromJSON build a registration from a JSON body

func SoftwareFromJSON

func SoftwareFromJSON(data io.Reader) (*Software, *AppError)

SoftwareFromJSON build a user from a JSON body

func SoftwarePatchFromJSON

func SoftwarePatchFromJSON(data io.Reader) (*SoftwarePatch, *AppError)

SoftwarePatchFromJSON build a user from a JSON body

func SubscriptionFromJSON

func SubscriptionFromJSON(data io.Reader) (*Subscription, *AppError)

SubscriptionFromJSON build a user from a JSON body

func SubscriptionPatchFromJSON

func SubscriptionPatchFromJSON(data io.Reader) (*SubscriptionPatch, *AppError)

SubscriptionPatchFromJSON build a user from a JSON body

func TagFromJSON

func TagFromJSON(data io.Reader) (*Tag, *AppError)

TagFromJSON build a user from a JSON body

func TagPatchFromJSON

func TagPatchFromJSON(data io.Reader) (*TagPatch, *AppError)

TagPatchFromJSON build a user from a JSON body

func ToJSON

func ToJSON(o interface{}) []byte

ToJSON build the JSON body from a struct

func UserFromJSON

func UserFromJSON(data io.Reader) (*User, *AppError)

UserFromJSON build a user from a JSON body

func UserPatchFromJSON

func UserPatchFromJSON(data io.Reader) (*UserPatch, *AppError)

UserPatchFromJSON build a user from a JSON body

Types

type AppError

type AppError struct {
	Path          string `json:"-"`           // File path where the error occured
	In            string `json:"-"`           // Function name where the error occured
	InternalError error  `json:"-"`           // Admin error that will be logged on server side
	Message       string `json:"message"`     // End user message that describe the error
	StatusCode    int    `json:"status_code"` // HTTP status code that is supposed to be returned if error occurs
}

AppError structure

func FromJSON

func FromJSON(o interface{}, data io.Reader) *AppError

FromJSON build a structure from a JSON body

func IsValidEmail

func IsValidEmail(email string) *AppError

IsValidEmail check wether the email is valid

func IsValidPassword

func IsValidPassword(password string) *AppError

IsValidPassword check wether the password is valid

func IsValidUsername

func IsValidUsername(username string) *AppError

IsValidUsername check wether the username is valid

func NewAppError

func NewAppError(path string, in string, err error, message string, statusCode int) *AppError

NewAppError build a new app error

func NewInternalAppError

func NewInternalAppError(path string, in string, err error) *AppError

NewInternalAppError build a new internal app error

func (*AppError) String

func (o *AppError) String() string

String return a formatted string

func (*AppError) ToJSON

func (o *AppError) ToJSON() []byte

ToJSON build the JSON body from a struct

type Auth

type Auth struct {
	Username string `json:"username" binding:"required"`
	Password string `json:"password" binding:"required"`
}

Auth structure

func (*Auth) IsValid

func (o *Auth) IsValid() *AppError

IsValid return wether the registration data is valid

type Categories

type Categories []Category

Categories structure

func (*Categories) ToJSON

func (o *Categories) ToJSON() []byte

ToJSON build the JSON body from the struct

type Category

type Category struct {
	Name string `json:"name" binding:"required"`
}

Category structure

func (*Category) IsValid

func (o *Category) IsValid() *AppError

IsValid return wether the category data is valid

func (*Category) PreSave

func (o *Category) PreSave() *AppError

PreSave clean object before saving to store

func (*Category) ToJSON

func (o *Category) ToJSON() []byte

ToJSON build the JSON body from a struct

type Info

type Info struct {
	ApplicationName      string `json:"application_name"`
	ApplicationVersion   string `json:"application_version"`
	ApplicationCommit    string `json:"application_commit"`
	ApplicationBuildTime string `json:"application_build_time"`
}

Info structure

func (*Info) ToJSON

func (o *Info) ToJSON() []byte

ToJSON build the JSON body from a struct

type Model

type Model struct {
	CreatedAt time.Time `json:"created_at,omitempty" db:"created_at"`
	UpdatedAt time.Time `json:"updated_at,omitempty" db:"updated_at"`
}

Model structure

type Notification

type Notification struct {
	Software   Software
	NewVersion Version
}

Notification is composed of a software, a new version and its severity

type Registration

type Registration struct {
	Username             string `json:"username" binding:"required"`
	Email                string `json:"email" binding:"required"`
	EmailConfirmation    string `json:"email_confirmation" binding:"required"`
	Password             string `json:"password" binding:"required"`
	PasswordConfirmation string `json:"password_confirmation" binding:"required"`
}

Registration structure

func (*Registration) IsValid

func (o *Registration) IsValid() *AppError

IsValid return wether the registration data is valid

func (*Registration) NewUser

func (o *Registration) NewUser() *User

NewUser return a new user based on registration data

type Roles

type Roles string

Roles type

func NewRoles

func NewRoles(roles ...string) Roles

NewRoles build a new set of roles

func (Roles) HasRole

func (o Roles) HasRole(role string) bool

HasRole check wether roles has the asked role

func (Roles) ToList

func (o Roles) ToList() []string

ToList return a slice of Roles

type Software

type Software struct {
	Model
	ID               uint64     `json:"id,omitempty" db:"id"`
	Name             string     `json:"name" db:"name"`
	Description      string     `json:"description" db:"description"`
	Repository       string     `json:"repository" db:"repository"`
	RepositoryType   string     `json:"repository_type" db:"repository_type"`
	Website          string     `json:"website" db:"website"`
	Version          string     `json:"version" db:"version"`
	VersionUpdatedAt *time.Time `json:"version_updated_at" db:"version_updated_at"`
	CreatedBy        uint64     `json:"created_by" db:"created_by"`
}

Software structure

func (*Software) FromPatch

func (o *Software) FromPatch(patch *SoftwarePatch)

FromPatch merge patch user into current user

func (*Software) IsValid

func (o *Software) IsValid() *AppError

IsValid return wether the software data is valid

func (*Software) ToJSON

func (o *Software) ToJSON() []byte

ToJSON build the JSON body from a struct

type SoftwarePatch

type SoftwarePatch struct {
	Name           *string `json:"name,omitempty"`
	Description    *string `json:"description,omitempty"`
	Repository     *string `json:"repository,omitempty"`
	RepositoryType *string `json:"repository_type,omitempty"`
	Website        *string `json:"website,omitempty"`
}

SoftwarePatch structure

func (*SoftwarePatch) NewSoftware

func (o *SoftwarePatch) NewSoftware(userID uint64) *Software

NewSoftware return a new user based on patch data

type Softwares

type Softwares []Software

Softwares structure

func (*Softwares) ToJSON

func (o *Softwares) ToJSON() []byte

ToJSON build the JSON body from the struct

type Subscription

type Subscription struct {
	Model

	UserID     uint64 `json:"-" db:"appuser_id"`
	SoftwareID uint64 `json:"-" db:"software_id"`

	Severity string `json:"severity" db:"severity"`

	*Software `json:",inline" db:"-"`
	Tags      *Tags `json:"tags,omitempty" db:"-"`
}

Subscription structure

func (*Subscription) FromPatch

func (o *Subscription) FromPatch(patch *SubscriptionPatch)

FromPatch merge patch subscription into current subscription

func (*Subscription) IsValid

func (o *Subscription) IsValid() *AppError

IsValid return wether the software data is valid

func (*Subscription) ToJSON

func (o *Subscription) ToJSON() []byte

ToJSON build the JSON body from a struct

type SubscriptionPatch

type SubscriptionPatch struct {
	Severity *string `json:"severity"`
}

SubscriptionPatch structure

func (*SubscriptionPatch) NewSubscription

func (o *SubscriptionPatch) NewSubscription(userID uint64, softwareID uint64) *Subscription

NewSubscription return a new subscription based on patch data

type Subscriptions

type Subscriptions []Subscription

Subscriptions structure

func (*Subscriptions) ToJSON

func (o *Subscriptions) ToJSON() []byte

ToJSON build the JSON body from the struct

type Tag

type Tag struct {
	Model

	ID        uint64 `json:"id" db:"id"`
	UserID    uint64 `json:"user_id" db:"appuser_id"`
	Name      string `json:"name" db:"name"`
	Color     string `json:"color" db:"color"`
	TextLight bool   `json:"text_light" db:"text_light"`
}

Tag structure

func (*Tag) FromPatch

func (o *Tag) FromPatch(patch *TagPatch)

FromPatch merge patch user into current user

func (*Tag) IsValid

func (o *Tag) IsValid() *AppError

IsValid return wether the tag data is valid

func (*Tag) ToJSON

func (o *Tag) ToJSON() []byte

ToJSON build the JSON body from a struct

type TagPatch

type TagPatch struct {
	Name      *string `json:"name,omitempty"`
	Color     *string `json:"color,omitempty"`
	TextLight *bool   `json:"text_light,omitempty"`
}

TagPatch structure

type Tags

type Tags []Tag

Tags structure

func (*Tags) ToJSON

func (o *Tags) ToJSON() []byte

ToJSON build the JSON body from the struct

type Token

type Token struct {
	Token string `json:"token"`
}

Token structure when passing the JWT

type User

type User struct {
	Model

	ID            uint64 `json:"id,omitempty" db:"id"`
	Username      string `json:"username" db:"username"`
	Email         string `json:"email" db:"email"`
	EmailVerified bool   `json:"email_verified" db:"email_verified"`
	Password      string `json:"-,omitempty" db:"-"`
	PasswordHash  string `json:"-" db:"password_hash"`
	Roles         Roles  `json:"roles" db:"roles"`
}

User structure

func (*User) FromPatch

func (o *User) FromPatch(patch *UserPatch)

FromPatch merge patch user into current user

func (*User) IsValid

func (o *User) IsValid() *AppError

IsValid return wether the user data is valid

func (*User) PreSave

func (o *User) PreSave() *AppError

PreSave clean object before saving to store

func (*User) ToJSON

func (o *User) ToJSON() []byte

ToJSON build the JSON body from a struct

type UserNotifications

type UserNotifications struct {
	User          *User
	Notifications []*Notification
}

UserNotifications is composed of a user and a list of notifications

type UserPatch

type UserPatch struct {
	Username *string `json:"name,omitempty"`
	Email    *string `json:"email,omitempty"`
	Password *string `json:"password,omitempty"`
}

UserPatch structure

func (*UserPatch) IsValid

func (o *UserPatch) IsValid() *AppError

IsValid return wether the user patch data is valid

func (*UserPatch) NewUser

func (o *UserPatch) NewUser() *User

NewUser return a new user based on patch data

type Users

type Users []User

Users structure

func (*Users) ToJSON

func (o *Users) ToJSON() []byte

ToJSON build the JSON body from the struct

type Version

type Version struct {
	Major      string
	Minor      string
	Patch      string
	PreRelease string
}

Version is a struct defining a version x.y.z

func NewVersion

func NewVersion(s string) *Version

NewVersion parse a string into a new version

func (*Version) Compare

func (v *Version) Compare(n *Version) string

Compare new version to current and extract upgrade severity

func (*Version) String

func (v *Version) String() string

String allows to print a version

Jump to

Keyboard shortcuts

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