Documentation
¶
Index ¶
- Constants
- Variables
- func AuthHandler(c *gin.Context)
- func AuthRenewHandler(c *gin.Context)
- func BuildToken(u User) string
- func DecodeEvent(e Eventer, i interface{}) error
- func DocHandler(c *gin.Context)
- func EntityHandler(c *gin.Context)
- func EventsDocHandler(c *gin.Context)
- func HTTPEventHandler(c *gin.Context)
- func ToMap(i interface{}) map[string]interface{}
- func UpHandler(c *gin.Context)
- type APPDocs
- type Aggregator
- type App
- func (app *App) AddEndpoint(e Endpoint)
- func (app *App) AddRoles(roles ...Role)
- func (app *App) Auth(evh ...EventHandler)
- func (app *App) CheckReference(e, k, value string, null bool) error
- func (app *App) Entity(name, id string) (*Entity, uint64, error)
- func (app *App) GenDocs() APPDocs
- func (app *App) HandleEvent(entityName, id, accid, userid, role string, ev Eventer, versionLock uint64) (string, uint64, error)
- func (app *App) RegisterEntity(e *EntityConf) *App
- func (app *App) Run(port string) error
- func (app *App) SessionTTL(d string)
- func (app *App) String() string
- type BaseEvent
- type BasicEntity
- type CRUDHandler
- func (ch CRUDHandler) CheckBase(e Eventer) bool
- func (ch CRUDHandler) CreateEvent() string
- func (ch CRUDHandler) DeletedEvent() string
- func (ch CRUDHandler) EventName() []string
- func (ch CRUDHandler) Handle(id string, accountid, userid, role string, ev Eventer, en *Entity, replay bool) (StoreOptions, error)
- func (ch CRUDHandler) UnDeletedEvent() string
- func (ch CRUDHandler) UpdateEvent() string
- type Endpoint
- type Entity
- type EntityConf
- func (e *EntityConf) AddCRUD(checkVersion bool) *EntityConf
- func (e *EntityConf) AddEventHandler(eh ...EventHandler) error
- func (e *EntityConf) AddValidator(v ...Validator) error
- func (ec *EntityConf) Aggregate(id string, events chan Eventer) (*Entity, error)
- func (e *EntityConf) Reference(en, k string, null bool)
- func (e *EntityConf) SetBaseStruct(i interface{})
- type EntityProperty
- type EntityReference
- type Event
- func (e *Event) ClearData()
- func (e *Event) GetData() map[string]interface{}
- func (e *Event) GetId() string
- func (e *Event) GetLinks() []string
- func (e *Event) GetStream() string
- func (e *Event) GetType() string
- func (e *Event) GetVersion() uint64
- func (e *Event) Has(k string) bool
- func (e *Event) SetData(k string, i interface{})
- func (e *Event) SetStructData(i interface{}) error
- func (event *Event) String() string
- type EventHandler
- type EventStore
- type Eventer
- type Group
- type Reader
- type Role
- type SessionClaims
- type SimpleValidator
- type StoreOptions
- type User
- type UserEventHandler
- type Validator
- type View
- type Viewer
Constants ¶
View Source
const ( EventTypeHeader = "X-Event" EntityVersionHeader = "X-LockVersion" CreateEventHeader = "X-Create" EntityHeader = "X-Entity" EventIDHeader = "X-EventID" EntityGroupHeader = "X-Group" SessionHeader = "X-Session" UserHeader = "X-User" CookieName = "san" )
View Source
const ( Created = "Created" Updated = "Updated" Deleted = "Deleted" )
View Source
const ( RebuiltOpt = "rebuild" PurgeOpt = "purge" )
View Source
const (
AllRole = "all"
)
View Source
const (
GroupEntity = "groups"
)
View Source
const UserCreatedEvent = "UserCreated"
View Source
const (
UserEntity = "users"
)
View Source
const UserTokenUpdated = "UserTokenUpdated"
Variables ¶
View Source
var ( InvalidEntityError = errors.New("Invalid entity in command") InvalidReferenceError = errors.New("Invalid reference") BaseUnseted = errors.New("Basestruct not set, should be setted") )
View Source
var ( FailStoreError = errors.New("Failed to store event, db issue") LockVersionError = errors.New("Invalid lock version") StreamNotFoundError = errors.New("Stream don't exist") )
View Source
var (
EntityDeleted = errors.New("Entity deleted, new to undeletet to update")
)
Functions ¶
func AuthHandler ¶
func AuthHandler(c *gin.Context)
func AuthRenewHandler ¶
func AuthRenewHandler(c *gin.Context)
func BuildToken ¶
func DecodeEvent ¶
func DocHandler ¶
func DocHandler(c *gin.Context)
func EntityHandler ¶
func EntityHandler(c *gin.Context)
func EventsDocHandler ¶
func EventsDocHandler(c *gin.Context)
func HTTPEventHandler ¶
func HTTPEventHandler(c *gin.Context)
Types ¶
type APPDocs ¶
type APPDocs struct { Name string `json:"name"` Version string `json:"version"` Entities map[string][]string `json:"entities"` Endpoints []Endpoint `json:"endpoints"` }
func GenerateDocs ¶
type Aggregator ¶
type Aggregator interface {
Aggregate(id string, entity interface{})
}
type App ¶
type App struct { Version string `json:"version"` Name string `json:"name"` Port string `json:"port"` // main log stream MainLog string `json:"mlog"` // Documentations BaseURL string `json:"baseURL"` Endpoints []Endpoint `json:"endpoints"` // user roles for auth Roles map[string]Role `json:"roles"` Entities map[string]*EntityConf `json:"entities"` Store EventStore `json:"-"` // Gin router Router *gin.Engine // turn off auth service check FirstRun bool `json:"firtRun"` AuthOff bool `json:"authOff"` Secret string `json:"-"` SessionValidity string `json:"sessionValidity"` Domain string `json:"sessionDomain"` LoginReferers []string `json:"loginReferers"` // contains filtered or unexported fields }
func NewApp ¶
func NewApp(name string, store EventStore) *App
func (*App) AddEndpoint ¶
func (*App) HandleEvent ¶
func (*App) RegisterEntity ¶
func (app *App) RegisterEntity(e *EntityConf) *App
func (*App) SessionTTL ¶
type BasicEntity ¶
type CRUDHandler ¶
type CRUDHandler struct { EntityName string `json:"entityName"` CheckVersion bool `json:"checkVersion"` }
func NewCRUDHandler ¶
func NewCRUDHandler(name string) CRUDHandler
func (CRUDHandler) CheckBase ¶
func (ch CRUDHandler) CheckBase(e Eventer) bool
func (CRUDHandler) CreateEvent ¶
func (ch CRUDHandler) CreateEvent() string
func (CRUDHandler) DeletedEvent ¶
func (ch CRUDHandler) DeletedEvent() string
func (CRUDHandler) EventName ¶
func (ch CRUDHandler) EventName() []string
func (CRUDHandler) Handle ¶
func (ch CRUDHandler) Handle(id string, accountid, userid, role string, ev Eventer, en *Entity, replay bool) (StoreOptions, error)
Handler CRUD events
func (CRUDHandler) UnDeletedEvent ¶
func (ch CRUDHandler) UnDeletedEvent() string
func (CRUDHandler) UpdateEvent ¶
func (ch CRUDHandler) UpdateEvent() string
type Endpoint ¶
type Endpoint struct { Path string `json:"path"` Method string `json:"method"` Description string `json:"description,omitempty"` ExampleBody string `json:"exampleBody,omitempty"` }
func NewEndpoint ¶
type Entity ¶
type EntityConf ¶
type EntityConf struct { Name string `json:"name"` CRUD bool `json:"crud"` Description string `json:"desc"` // basic entity prefix StreamPrefix string `json:"stream_prefix"` CorrelationStream string `json:"correlation_stream"` // Entity ID references EntityReferences []EntityReference `json:"references"` // Event Handlers/Aggregators EventHandlers map[string]EventHandler `json:"handlers"` Validators map[string]Validator `json:"validators"` BaseStruct interface{} `json:"base,omitempty"` BaseSeted bool ReadRoles []string `json:"roles,omitempty"` }
func NewEntityConf ¶
func NewEntityConf(name string) *EntityConf
func (*EntityConf) AddCRUD ¶
func (e *EntityConf) AddCRUD(checkVersion bool) *EntityConf
func (*EntityConf) AddEventHandler ¶
func (e *EntityConf) AddEventHandler(eh ...EventHandler) error
func (*EntityConf) AddValidator ¶
func (e *EntityConf) AddValidator(v ...Validator) error
func (*EntityConf) Aggregate ¶
func (ec *EntityConf) Aggregate(id string, events chan Eventer) (*Entity, error)
func (*EntityConf) Reference ¶
func (e *EntityConf) Reference(en, k string, null bool)
func (*EntityConf) SetBaseStruct ¶
func (e *EntityConf) SetBaseStruct(i interface{})
type EntityProperty ¶
func NewProperty ¶
func NewProperty(name string) *EntityProperty
func (*EntityProperty) Email ¶
func (ep *EntityProperty) Email() *EntityProperty
func (*EntityProperty) ID ¶
func (ep *EntityProperty) ID() *EntityProperty
func (*EntityProperty) IP ¶
func (ep *EntityProperty) IP() *EntityProperty
func (*EntityProperty) NotNull ¶
func (ep *EntityProperty) NotNull() *EntityProperty
func (*EntityProperty) String ¶
func (ep *EntityProperty) String() *EntityProperty
func (*EntityProperty) URL ¶
func (ep *EntityProperty) URL() *EntityProperty
type EntityReference ¶
type Event ¶
type Event struct { BaseEvent Group string `json:"group,omitempty"` Entity string `json:"ent,omitepty"` CorrelationStream string `json:"cid,omitempty"` EntityID string `json:"id,omitempty"` StreamPrefix string `json:"streamPre,omitempty"` EventData map[string]interface{} `json:"data,omitempty"` }
func (*Event) GetVersion ¶
func (*Event) SetStructData ¶
type EventHandler ¶
type EventStore ¶
type EventStore interface { Store(e Eventer, opt StoreOptions) (uint64, error) Range(streamid string) (chan Eventer, uint64) Version(streamid string) (uint64, error) Scan(streamid string, from, to uint64) chan Event }
Eventstore interface
type Group ¶
type Group struct { BasicEntity ID string `json:"id"` Data map[string]string `json:"data"` }
type Role ¶
type SessionClaims ¶
type SessionClaims struct { Username string `json:"use"` Role string `json:"rol"` jwt.StandardClaims }
func AuthToken ¶
func AuthToken(t, secret string) (*SessionClaims, error)
type SimpleValidator ¶
type SimpleValidator struct {
// contains filtered or unexported fields
}
func NewSimpleValidator ¶
func NewSimpleValidator(ep ...*EntityProperty) *SimpleValidator
func (SimpleValidator) GetName ¶
func (sv SimpleValidator) GetName() string
func (SimpleValidator) Validate ¶
func (sv SimpleValidator) Validate(e Entity) error
type StoreOptions ¶
type StoreOptions struct { LockVersion uint64 `json:"lockversion"` Retry bool `json:"retry"` Create bool `json:"create"` }
Storing event options
type User ¶
type User struct { Username string `json:"username"` Password string `json:"password"` Role string `json:"role"` Created time.Time `json:"created` AccountID string `json:"accid"` ActiveToken bool `json:"activeToken"` Token string `json:"token"` Groups []string `json:"groups"` Data map[string]interface{} `json:"data"` }
func (*User) CheckPassword ¶
func (*User) CheckToken ¶
func (*User) GenerateToken ¶
func (u *User) GenerateToken()
type UserEventHandler ¶
type UserEventHandler struct { }
func (UserEventHandler) CheckBase ¶
func (uh UserEventHandler) CheckBase(e Eventer) bool
func (UserEventHandler) EventName ¶
func (uh UserEventHandler) EventName() []string
func (UserEventHandler) Handle ¶
func (uh UserEventHandler) Handle(id, accid, userid, role string, event Eventer, entity *Entity, replay bool) (StoreOptions, error)
Source Files
¶
Click to show internal directories.
Click to hide internal directories.