entities

package
v0.0.0-...-d386c04 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2024 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	HeaderIdempotencyKey = "idempotency-key"
	HeaderWebhookId      = "webhook-id"
	HeaderWebhookTs      = "webhook-timestamp"
	HeaderWebhookSign    = "webhook-signature"
	HeaderWebhookRef     = "webhook-ref"
)
View Source
var (
	IdNsWs  = "ws"
	IdNsWsc = "wsc"
	IdNsApp = "app"
	IdNsEp  = "ep"
	IdNsEpr = "epr"
	IdNsMsg = "msg"
	IdNsReq = "req"
	IdNsRes = "res"
)
View Source
var (
	MetaAttId    = "kanthor.att.id"
	MetaAttState = "kanthor.att.state"
	MetaEprId    = "kanthor.epr.id"
)
View Source
var (
	TableWs  = project.NameWithoutTier("workspace")
	TableWsc = project.NameWithoutTier("workspace_credentials")
	TableApp = project.NameWithoutTier("application")
	TableEp  = project.NameWithoutTier("endpoint")
	TableEpr = project.NameWithoutTier("endpoint_rule")
	TableMsg = project.NameWithoutTier("message")
	TableReq = project.NameWithoutTier("request")
	TableRes = project.NameWithoutTier("response")
	TableAtt = project.NameWithoutTier("attempt")
)
View Source
var DefaultPagingLimitMax = 100
View Source
var DefaultPagingLimitMin = 5
View Source
var DefaultPagingPageMax = 100
View Source
var DefaultPagingPageMin = 1
View Source
var DefaultPagingQuery = &PagingQuery{
	Limit: DefaultPagingLimitMin,
	Page:  DefaultPagingPageMin,
}
View Source
var MessageMappers = map[string]func(doc *Message) any{
	"id":        func(doc *Message) any { return doc.Id },
	"timestamp": func(doc *Message) any { return doc.Timestamp },
	"tier":      func(doc *Message) any { return doc.Tier },
	"app_id":    func(doc *Message) any { return doc.AppId },
	"type":      func(doc *Message) any { return doc.Type },
	"metadata":  func(doc *Message) any { return doc.Metadata.String() },
	"headers":   func(doc *Message) any { return doc.Headers.String() },
	"body":      func(doc *Message) any { return doc.Body },
}
View Source
var MessageProps = []string{
	"id",
	"timestamp",
	"tier",
	"app_id",
	"type",
	"metadata",
	"headers",
	"body",
}
View Source
var RequestMappers = map[string]func(doc *Request) any{
	"id":        func(doc *Request) any { return doc.Id },
	"timestamp": func(doc *Request) any { return doc.Timestamp },
	"msg_id":    func(doc *Request) any { return doc.MsgId },
	"ep_id":     func(doc *Request) any { return doc.EpId },
	"tier":      func(doc *Request) any { return doc.Tier },
	"app_id":    func(doc *Request) any { return doc.AppId },
	"type":      func(doc *Request) any { return doc.Type },
	"metadata":  func(doc *Request) any { return doc.Metadata.String() },
	"headers":   func(doc *Request) any { return doc.Headers.String() },
	"body":      func(doc *Request) any { return doc.Body },
	"uri":       func(doc *Request) any { return doc.Uri },
	"method":    func(doc *Request) any { return doc.Method },
}
View Source
var RequestProps = []string{
	"id",
	"timestamp",
	"msg_id",
	"ep_id",
	"tier",
	"app_id",
	"type",
	"metadata",
	"headers",
	"body",
	"uri",
	"method",
}
View Source
var ResponseMappers = map[string]func(doc *Response) any{
	"id":        func(doc *Response) any { return doc.Id },
	"timestamp": func(doc *Response) any { return doc.Timestamp },
	"msg_id":    func(doc *Response) any { return doc.MsgId },
	"ep_id":     func(doc *Response) any { return doc.EpId },
	"req_id":    func(doc *Response) any { return doc.ReqId },
	"tier":      func(doc *Response) any { return doc.Tier },
	"app_id":    func(doc *Response) any { return doc.AppId },
	"type":      func(doc *Response) any { return doc.Type },
	"metadata":  func(doc *Response) any { return doc.Metadata.String() },
	"headers":   func(doc *Response) any { return doc.Headers.String() },
	"body":      func(doc *Response) any { return doc.Body },
	"uri":       func(doc *Response) any { return doc.Uri },
	"status":    func(doc *Response) any { return doc.Status },
	"error":     func(doc *Response) any { return doc.Error },
}
View Source
var ResponseProps = []string{
	"id",
	"timestamp",
	"msg_id",
	"ep_id",
	"req_id",
	"tier",
	"app_id",
	"type",
	"metadata",
	"headers",
	"body",
	"uri",
	"status",
	"error",
}

Functions

This section is empty.

Types

type Application

type Application struct {
	Entity
	AuditTime

	WsId string
	Name string
}

func (*Application) Marshal

func (entity *Application) Marshal() ([]byte, error)

func (*Application) String

func (entity *Application) String() string

func (*Application) TableName

func (entity *Application) TableName() string

func (*Application) Unmarshal

func (entity *Application) Unmarshal(data []byte) error

func (*Application) Validate

func (entity *Application) Validate() error

type ApplicationWithRelationship

type ApplicationWithRelationship struct {
	*Application
	Workspace *Workspace
}

type Attempt

type Attempt struct {
	ReqId string

	MsgId string
	EpId  string
	AppId string
	Tier  string

	AttemptState
}

func (*Attempt) Id

func (entity *Attempt) Id() string

func (*Attempt) Marshal

func (entity *Attempt) Marshal() ([]byte, error)

func (*Attempt) String

func (entity *Attempt) String() string

func (*Attempt) TableName

func (entity *Attempt) TableName() string

func (*Attempt) Unmarshal

func (entity *Attempt) Unmarshal(data []byte) error

type AttemptState

type AttemptState struct {
	ScheduleCounter int    `json:"schedule_counter"`
	ScheduleNext    int64  `json:"schedule_next"`
	ScheduledAt     int64  `json:"scheduled_at"`
	CompletedAt     int64  `json:"completed_at"`
	CompletedId     string `json:"completed_id"`
}

func (*AttemptState) String

func (entity *AttemptState) String() string

type AttemptTask

type AttemptTask struct {
	AppId string
	EpId  string
	To    int64
	From  int64

	Init int64
}

func (*AttemptTask) Marshal

func (entity *AttemptTask) Marshal() ([]byte, error)

func (*AttemptTask) String

func (entity *AttemptTask) String() string

func (*AttemptTask) Unmarshal

func (entity *AttemptTask) Unmarshal(data []byte) error

type AttemptTrigger

type AttemptTrigger struct {
	To   int64
	From int64

	Init int64
}

func (*AttemptTrigger) Marshal

func (entity *AttemptTrigger) Marshal() ([]byte, error)

func (*AttemptTrigger) String

func (entity *AttemptTrigger) String() string

func (*AttemptTrigger) Unmarshal

func (entity *AttemptTrigger) Unmarshal(data []byte) error

type AuditTime

type AuditTime struct {
	// I didn't find a way to disable automatic fields modify yet
	// so, I use a tag to disable this feature here
	// but, we should keep our entities stateless if we can
	CreatedAt int64 `gorm:"autoCreateTime:false"`
	UpdatedAt int64 `gorm:"autoUpdateTime:false"`
}

func (*AuditTime) SetAT

func (entity *AuditTime) SetAT(now time.Time)

type Endpoint

type Endpoint struct {
	Entity
	AuditTime

	SecretKey string

	AppId string
	Name  string
	// HTTP: POST/PUT/PATCH
	Method string
	// format: scheme ":" ["//" authority] path ["?" query] ["#" fragment]
	// HTTP: https:://httpbentity.org/post?app=kanthor.webhook
	// gRPC: grpc:://app.kanthorlabs.com
	Uri string
}

func (*Endpoint) GenSecretKey

func (entity *Endpoint) GenSecretKey()

func (*Endpoint) TableName

func (entity *Endpoint) TableName() string

func (*Endpoint) Validate

func (entity *Endpoint) Validate() error

type EndpointMessage

type EndpointMessage struct {
	Message
	RequestCount     int
	RequestLatestTs  int64
	ResponseCount    int
	ResponseLatestTs int64
	SuccessId        string
}

type EndpointRule

type EndpointRule struct {
	Entity
	AuditTime

	EpId string
	Name string

	Priority int32
	// the logic of not-false is true should be used here
	// to guarantee default all rule will be on include mode
	Exclusionary bool

	// examples
	//  - type
	//  - app_id
	ConditionSource string
	// examples:
	// 	- any::
	// 	- equal::orders.paid
	// 	- prefix::orders.
	ConditionExpression string
}

func (*EndpointRule) TableName

func (entity *EndpointRule) TableName() string

func (*EndpointRule) Validate

func (entity *EndpointRule) Validate() error

type Entity

type Entity struct {
	Id string
}
type Header map[string][]string

func (Header) Add

func (h Header) Add(key, value string)

func (Header) Del

func (h Header) Del(key string)

func (Header) FromHTTP

func (h Header) FromHTTP(headers http.Header)

func (Header) Get

func (h Header) Get(key string) string

func (Header) Merge

func (h Header) Merge(src Header)

func (*Header) Scan

func (h *Header) Scan(value interface{}) error

Scan implements the Scanner interface.

func (Header) Set

func (h Header) Set(key, value string)

func (Header) String

func (h Header) String() string

func (Header) ToHTTP

func (h Header) ToHTTP() http.Header

func (Header) Value

func (h Header) Value() (driver.Value, error)

Value implements the driver Valuer interface.

func (Header) Values

func (h Header) Values(key string) []string

type Message

type Message struct {
	TSEntity

	Tier     string
	AppId    string
	Type     string
	Metadata Metadata
	Headers  Header
	Body     string
}

func (*Message) Marshal

func (entity *Message) Marshal() ([]byte, error)

func (*Message) String

func (entity *Message) String() string

func (*Message) TableName

func (entity *Message) TableName() string

func (*Message) Unmarshal

func (entity *Message) Unmarshal(data []byte) error

type Metadata

type Metadata map[string]string

func (Metadata) Get

func (meta Metadata) Get(key string) string

func (Metadata) Merge

func (meta Metadata) Merge(src map[string]string)

func (*Metadata) Scan

func (meta *Metadata) Scan(value interface{}) error

Scan implements the Scanner interface.

func (Metadata) Set

func (meta Metadata) Set(key, value string)

func (Metadata) String

func (meta Metadata) String() string

func (Metadata) Value

func (meta Metadata) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type PagingQuery

type PagingQuery struct {
	Search string
	Limit  int
	Page   int
	Ids    []string
}

func PagingQueryFromGatewayQuery

func PagingQueryFromGatewayQuery(query *gateway.Query) *PagingQuery

func (*PagingQuery) Validate

func (q *PagingQuery) Validate() error

type RecoveryTask

type RecoveryTask struct {
	AppId string
	To    int64
	From  int64

	Init int64
}

func (*RecoveryTask) Marshal

func (entity *RecoveryTask) Marshal() ([]byte, error)

func (*RecoveryTask) String

func (entity *RecoveryTask) String() string

func (*RecoveryTask) Unmarshal

func (entity *RecoveryTask) Unmarshal(data []byte) error

type Request

type Request struct {
	TSEntity

	EpId  string
	MsgId string

	Tier     string
	AppId    string
	Type     string
	Metadata Metadata

	// HTTP: POST/PUT/PATCH
	Headers Header
	Body    string
	Uri     string
	Method  string
}

func (*Request) Marshal

func (entity *Request) Marshal() ([]byte, error)

func (*Request) String

func (entity *Request) String() string

func (*Request) TableName

func (entity *Request) TableName() string

func (*Request) Unmarshal

func (entity *Request) Unmarshal(data []byte) error

type Response

type Response struct {
	TSEntity

	EpId  string
	MsgId string
	ReqId string

	Tier     string
	AppId    string
	Type     string
	Metadata Metadata

	Headers Header
	Body    string
	Uri     string
	Status  int
	Error   string
}

func (*Response) Marshal

func (entity *Response) Marshal() ([]byte, error)

func (*Response) String

func (entity *Response) String() string

func (*Response) TableName

func (entity *Response) TableName() string

func (*Response) Unmarshal

func (entity *Response) Unmarshal(data []byte) error

type ScanningQuery

type ScanningQuery struct {
	Search string
	Size   int
	From   time.Time
	To     time.Time
}

func ScanningQueryFromGatewayQuery

func ScanningQueryFromGatewayQuery(query *gateway.Query, timer timer.Timer) *ScanningQuery

func (*ScanningQuery) Validate

func (q *ScanningQuery) Validate() error

type ScanningResult

type ScanningResult[T any] struct {
	Data  T
	Error error
}

type TSEntity

type TSEntity struct {
	Id        string
	Timestamp int64
}

TSEntity is time series entity

func (*TSEntity) SetTS

func (entity *TSEntity) SetTS(now time.Time)

type Workspace

type Workspace struct {
	Entity
	AuditTime

	OwnerId string
	Name    string
	Tier    string
}

func (*Workspace) TableName

func (entity *Workspace) TableName() string

func (*Workspace) Validate

func (entity *Workspace) Validate() error

type WorkspaceCredentials

type WorkspaceCredentials struct {
	Entity
	AuditTime

	WsId      string
	Name      string
	Hash      string
	ExpiredAt int64
}

func (*WorkspaceCredentials) TableName

func (entity *WorkspaceCredentials) TableName() string

func (*WorkspaceCredentials) Validate

func (entity *WorkspaceCredentials) Validate() error

type WorkspaceSnapshot

type WorkspaceSnapshot struct {
	Id           string
	Name         string
	Applications map[string]WorkspaceSnapshotApp
}

type WorkspaceSnapshotApp

type WorkspaceSnapshotApp struct {
	Name      string
	Endpoints map[string]WorkspaceSnapshotEp
}

type WorkspaceSnapshotEp

type WorkspaceSnapshotEp struct {
	Name   string
	Method string
	Uri    string
	Rules  map[string]WorkspaceSnapshotEpr
}

type WorkspaceSnapshotEpr

type WorkspaceSnapshotEpr struct {
	Name                string
	Priority            int32
	Exclusionary        bool
	ConditionSource     string
	ConditionExpression string
}

Jump to

Keyboard shortcuts

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