Documentation ¶
Index ¶
- func SyncServiceWitManifest(sm ServiceManifest) (err error)
- type Base
- type Callback
- type CallbackAssignable
- type Event
- type NIDBase
- type Namespace
- type PriorityGroup
- type PriorityGroupAssignable
- type RetryPolicy
- type RetryPolicyAssignable
- type Service
- func (s *Service) BeforeCreate(tx *gorm.DB) (err error)
- func (s *Service) BeforeSave(tx *gorm.DB) error
- func (s *Service) Delete() (err error)
- func (s *Service) FindCallback(n string) (*Callback, error)
- func (s *Service) GetCallbacks() (callbacks []Callback, err error)
- func (s *Service) GetPriorityGroups() ([]PriorityGroup, error)
- func (s *Service) GetRetryPolicies() ([]RetryPolicy, error)
- func (s *Service) GetServiceManifest() (ServiceManifest, error)
- func (s *Service) GetURL() *url.URL
- func (s Service) MarshalJSON() ([]byte, error)
- func (s *Service) PK() string
- func (s *Service) Store() error
- func (s *Service) Update() error
- type ServiceManifest
- type Token
- type Topic
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SyncServiceWitManifest ¶
func SyncServiceWitManifest(sm ServiceManifest) (err error)
SyncServiceWitManifest assert a service along with all of its depndencies in a single transactions
Types ¶
type Callback ¶
type Callback struct { Base CallbackAssignable Name string `json:"name" gorm:"<-:create;uniqueIndex:idx_unique_service_callback"` ServiceID string `json:"-" gorm:"<-:create;notNull;uniqueIndex:idx_unique_service_callback;uniqueIndex:idx_unique_service_path;"` Service *Service `json:"-" gorm:"foreignKey:ServiceID;references:Name;"` RetryPolicyID sql.NullString `json:"-"` RetryPolicy *RetryPolicy `json:"retry_policy,omitempty" gorm:"foreignKey:RetryPolicyID,ServiceID;references:Name,ServiceID"` PriorityGroupID string `json:"-"` PriorityGroup *PriorityGroup `` /* 130-byte string literal not displayed */ Events []*Event `json:"-" gorm:"many2many:callbacks_events;constraint:OnDelete:CASCADE;"` }
Callback model
func (*Callback) BeforeSave ¶
BeforeSave prepares Callback model and resolves relationships before inserting it into database
func (Callback) MarshalJSON ¶
MarshalJSON serializes Callback struct to JSON representation
type CallbackAssignable ¶
type CallbackAssignable struct { Path string `json:"path" gorm:"notNull;uniqueIndex:idx_unique_service_path;"` Method string `json:"method" gorm:"notNull;check: method in ('GET', 'POST');"` Headers modelTypes.Headers `json:"headers"` RetryPolicyName string `json:"retry_policy_name" gorm:"-"` PriorityGroupName string `json:"priority_group_name" gorm:"-"` ListensTo []string `json:"listens_to" gorm:"-"` }
CallbackAssignable specifies mass assignable fields for
type Event ¶
type Event struct { Base Topic NamespaceID string `json:"-" gorm:"notNull;index;uniqueIndex:idx_unique_event_namespace;"` Namespace *Namespace `json:"-" gorm:"foreignKey:NamespaceID;references:Name;"` Callbacks []*Callback `json:"-" gorm:"many2many:callbacks_events;"` }
Event model
func AssertEvents ¶
AssertEvents inserts a set of events into databasae
func (Event) MarshalJSON ¶
MarshalJSON serializes Event struct to JSON representation
func (*Event) TopicString ¶
TopicString returns event topic as a string
type NIDBase ¶
type NIDBase struct { CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` }
NIDBase contains common columns for all tables without UUID
type Namespace ¶
type Namespace struct { Base Name string `json:"name" gorm:"unique;index;notNull;"` AccountID string `json:"account_id" gorm:"notNull;"` Events []*Event `json:"-" gorm:"foreignKey:NamespaceID;references:Name;constraint:OnDelete:CASCADE;"` Services []*Service `json:"-" gorm:"foreignKey:NamespaceID;references:Name;constraint:OnDelete:CASCADE;"` }
Namespace Model
func FindNamespace ¶
FindNamespace queries a namespaces by name and returns the first match
func (*Namespace) AlreadyTaken ¶
AlreadyTaken checks if the namespace is already registerd
func (Namespace) MarshalJSON ¶
MarshalJSON serializes Namespace struct into JSON representation
type PriorityGroup ¶
type PriorityGroup struct { NIDBase PriorityGroupAssignable Name string `json:"name" gorm:"<-:create;primaryKey;"` ServiceID string `json:"-" gorm:"primaryKey;"` Service *Service `json:"-" gorm:"foreignKey:ServiceID;references:Name;"` Callbacks []*Callback `json:"-" gorm:"foreignKey:PriorityGroupID,ServiceID;references:Name,ServiceID;constraint:OnDelete:RESTRICT;"` }
PriorityGroup model
func FindPriorityGroupInService ¶
func FindPriorityGroupInService(s string, p string) (*PriorityGroup, error)
FindPriorityGroupInService queries priority groups by name and service, returns the first exact match
func (*PriorityGroup) Delete ¶
func (p *PriorityGroup) Delete() error
Delete removes the priority group
func (*PriorityGroup) GetCallbacks ¶
func (p *PriorityGroup) GetCallbacks() ([]Callback, error)
GetCallbacks retrieves callbacks of a priority groups from database
func (PriorityGroup) MarshalJSON ¶
func (p PriorityGroup) MarshalJSON() ([]byte, error)
MarshalJSON returns the augmented JSON represnation of PriorityGroup model
func (*PriorityGroup) NumOfCallbacks ¶
func (p *PriorityGroup) NumOfCallbacks() (count int64, err error)
NumOfCallbacks returns count of callbacks associated with a priority group
func (*PriorityGroup) Store ¶
func (p *PriorityGroup) Store() error
Store inserts a new priority group record into the database
func (*PriorityGroup) Update ¶
func (p *PriorityGroup) Update() error
Update saves the current state of a priority record into the database
type PriorityGroupAssignable ¶
type PriorityGroupAssignable struct { MinWorkers uint `json:"min_workers" gorm:"default:1;check: min_workers > 0;"` MaxWorkers uint `json:"max_workers" gorm:"default:1;check: max_workers > 0;"` ConcurrencyPerWorker uint `json:"concurrency_per_worker" gorm:"default:4;check: max_workers > 0;"` ScaleUpThreshold uint `json:"scale_up_threshold" gorm:"default:150;"` ScaleDownThreshold uint `json:"scale_down_threshold" gorm:"default:50;"` }
PriorityGroupAssignable is specifies mass assignable fields for PriorityGroup model
type RetryPolicy ¶
type RetryPolicy struct { NIDBase RetryPolicyAssignable Name string `json:"name" gorm:"<-:create;primaryKey;"` ServiceID string `json:"-" gorm:"primaryKey;"` Service *Service `json:"-" gorm:"foreignKey:ServiceID;references:Name;constraint:false;"` Callbacks []*Callback `json:"-" gorm:"foreignKey:RetryPolicyID,ServiceID;references:Name,ServiceID;constraint:OnDelete:RESTRICT;"` }
RetryPolicy model
func FindRetryPolicyInService ¶
func FindRetryPolicyInService(s string, r string) (*RetryPolicy, error)
FindRetryPolicyInService queries priority groups by name and namespace, returns the first exact match
func (*RetryPolicy) NumOfCallbacks ¶
func (r *RetryPolicy) NumOfCallbacks() (count int64, err error)
NumOfCallbacks returns count of callbacks associated with the retry policy
func (*RetryPolicy) Store ¶
func (r *RetryPolicy) Store() error
Store persiste the new Retry Policy in the database
func (*RetryPolicy) Update ¶
func (r *RetryPolicy) Update() error
Update saves the current state of the retry policy record into the database
type RetryPolicyAssignable ¶
type RetryPolicyAssignable struct { MaxRetries uint `json:"max_retries" gorm:"default:3;check: max_retries > 1;"` ExpireAfter uint `json:"expire_after" gorm:"default:0;"` BackoffType string `json:"backoff_type" gorm:"notNull;check: backoff_type in ('linear', 'exponential');"` BackoffBase uint `json:"backoff_base" gorm:"default:2;check: backoff_base > 1;"` BackoffOffset uint `json:"backoff_offset" gorm:"default:4;check: backoff_offset > 1;"` }
RetryPolicyAssignable is specifies mass assignable fields for RetryPolicy model
type Service ¶
type Service struct { Base Name string `json:"name" gorm:"<-:create;notNull;index;unique;uniqueIndex:idx_unique_service_name_namespace;"` Scheme string `json:"-" gorm:"notNull;"` Host string `json:"-" gorm:"notNull;unique;index;"` URL string `json:"url" gorm:"-"` Headers modelTypes.Headers `json:"headers"` NamespaceID string `json:"-" gorm:"notNull;index;uniqueIndex:idx_unique_service_name_namespace;"` Namespace *Namespace `json:"-" gorm:"foreignKey:NamespaceID;references:Name;"` PriorityGroups []*PriorityGroup `json:"-" gorm:"foreignKey:ServiceID;references:Name;constraint:OnDelete:CASCADE;"` Callbacks []*Callback `json:"-" gorm:"foreignKey:ServiceID;references:Name;constraint:OnDelete:CASCADE;"` RetryPolicies []*RetryPolicy `json:"-" gorm:"foreignKey:ServiceID;references:Name;constraint:OnDelete:CASCADE;"` }
Service model
func FindServiceInNamespace ¶
FindServiceInNamespace queries servcies by name and namespace and returns the first exact match
func (*Service) BeforeCreate ¶
BeforeCreate prefixes service name with namespace to ensure its uniquness
func (*Service) BeforeSave ¶
BeforeSave prepares Service model and sanitizes data before being inserted into database
func (*Service) FindCallback ¶
FindCallback queries associated callbacks of the service by name. It returns an exact match.
func (*Service) GetCallbacks ¶
GetCallbacks retrieves callbacks of a service from database
func (*Service) GetPriorityGroups ¶
func (s *Service) GetPriorityGroups() ([]PriorityGroup, error)
GetPriorityGroups retrieves service priority groups from database
func (*Service) GetRetryPolicies ¶
func (s *Service) GetRetryPolicies() ([]RetryPolicy, error)
GetRetryPolicies retrieves service retry policies from database
func (*Service) GetServiceManifest ¶
func (s *Service) GetServiceManifest() (ServiceManifest, error)
GetServiceManifest returns manifest representation of the service
func (*Service) GetURL ¶
GetURL returns the URL object of the service. Service URL objects are consited of `Scheme` and `Host` only.
func (Service) MarshalJSON ¶
MarshalJSON returns the augmented JSON represnation of Service model
func (*Service) PK ¶
PK returns normalized primary key value for current instance The name of the service is the primary key and it's expected to be in the form of "namespace.service_name" format
type ServiceManifest ¶
type ServiceManifest struct { Service Service `json:"service"` PriorityGroups []PriorityGroup `json:"priority_groups"` RetryPolicies []RetryPolicy `json:"retry_policies"` Callbacks []Callback `json:"callbacks"` }
ServiceManifest value-object is used to describe the entirety of a service setup
type Token ¶
type Token struct { Base UUID uuid.UUID `gorm:"type:uuid;index;default:uuid_generate_v4();"` Key uuid.UUID `gorm:"type:uuid;index;default:uuid_generate_v4();"` ExpiresAt sql.NullTime AccountID string `gorm:"notNull;index;"` Service string `gorm:"notNull;index;default:'*'"` }
Token Model
func (*Token) AccountAlreadyRegisterd ¶
AccountAlreadyRegisterd checks to see if any token has been generated for account ID.
func (*Token) Namespaces ¶
Namespaces returns associated namespaces with the token account
type Topic ¶
type Topic struct { Domain string `json:"-" gorm:"uniqueIndex:idx_unique_event_namespace"` Resource string `json:"-" gorm:"uniqueIndex:idx_unique_event_namespace"` Operation string `json:"-" gorm:"uniqueIndex:idx_unique_event_namespace"` }
Topic is an auxilary type for Event model
func ParseTopicString ¶
ParseTopicString converts a string into a Topic struct