lib

package
v0.21.3 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2021 License: MIT Imports: 28 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// EventWatchBreak watch break event
	EventWatchBreak = &Event{Type: Brk, Value: nil}
	// EventWatchBreakBytes watch break event content
	EventWatchBreakBytes, _ = json.Marshal(EventWatchBreak)
)
View Source
var (
	//DefaultWriter default json writer
	DefaultWriter = func(resp *restful.Response, event *Event) bool {
		if err := codec.EncJsonWriter(event, resp.ResponseWriter); err != nil {
			blog.Errorf("defaultWriter error: %v", err)
			return false
		}
		return true
	}
)

Functions

func CopyMap

func CopyMap(s operator.M) (r operator.M)

CopyMap return a new operator.M copy from provided by depth=1

func FormatTime

func FormatTime(data []operator.M, needTimeFormatList []string)

FormatTime format time

func GetCustomCondition added in v0.20.15

func GetCustomCondition(req *restful.Request) *operator.Condition

GetCustomCondition get custom condition from req url and parameter

func GetQueryParamInt

func GetQueryParamInt(req *restful.Request, key string, defaultValue int) (int, error)

GetQueryParamInt get int from restful query parameter

func GetQueryParamInt64

func GetQueryParamInt64(req *restful.Request, key string, defaultValue int64) (int64, error)

GetQueryParamInt64 get int64 from restful query parameter

func GetQueryParamString

func GetQueryParamString(req *restful.Request, key string) string

GetQueryParamString get string from rest query parameter

func GetQueryParamStringArray

func GetQueryParamStringArray(req *restful.Request, key, sep string) []string

GetQueryParamStringArray get string array from restful query parameter

func MarkProcess

MarkProcess does the following things: 1. print log when a request comes in and returns. 2. print request body to log. 3. flow control.

func ReturnRest

func ReturnRest(resp *RestResponse)

ReturnRest common restfult response

Types

type Event

type Event struct {
	Type  EventType  `json:"type"`
	Value operator.M `json:"value"`
}

Event event of watch

type EventType

type EventType int32

EventType event type

const (
	// Nop no operation event
	Nop EventType = iota
	// Add add event
	Add
	// Del delete event
	Del
	// Chg change event
	Chg
	// SChg self change event
	SChg
	// Brk event
	Brk EventType = -1
)

type ExtraField

type ExtraField struct {
	// contains filtered or unexported fields
}

ExtraField extra field

func NewExtra

func NewExtra(raw string) *ExtraField

NewExtra create extra fields

func (*ExtraField) GetStr

func (ef *ExtraField) GetStr() (string, error)

GetStr get string value

func (*ExtraField) Unmarshal

func (ef *ExtraField) Unmarshal(r interface{}) (err error)

Unmarshal unmarshal extra field to struct

type Manager

type Manager struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Manager manager

func NewManager

func NewManager(sep int64, title string) *Manager

NewManager create manager

func (*Manager) Add

func (m *Manager) Add(t time.Duration)

Add add

func (*Manager) Flush

func (m *Manager) Flush()

Flush manager do flush

func (*Manager) Start

func (m *Manager) Start()

Start start

type RestResponse

type RestResponse struct {
	Resp     *restful.Response
	HTTPCode int

	Data    interface{}
	ErrCode int
	Message string
	Extra   map[string]interface{}

	WrapFunc func([]byte) []byte
}

RestResponse wrapper for restful Response

type Selector added in v0.20.15

type Selector struct {
	Prefix      string
	SelectorStr string
	// contains filtered or unexported fields
}

func (*Selector) Clear added in v0.20.15

func (s *Selector) Clear()

Clear reset the current cursor for labelSelector condition parsing

func (*Selector) GetAllConditions added in v0.20.15

func (s *Selector) GetAllConditions() []*operator.Condition

GetAllConditions get all conditions of labelSelector

func (*Selector) GetNextCondition added in v0.20.15

func (s *Selector) GetNextCondition() *operator.Condition

TODO: error operation GetNextCondition get next label selector condition unit

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store action for rest request

func NewStore

func NewStore(mDriver drivers.DB, eb *watchbus.EventBus) *Store

NewStore create store action

func (*Store) Count added in v0.20.15

func (a *Store) Count(ctx context.Context, resourceType string, opt *StoreGetOption) (int64, error)

Get get something from db according to request

func (*Store) CreateIndex added in v0.20.15

func (a *Store) CreateIndex(ctx context.Context, resourceType string, index drivers.Index) error

CreateIndex create single index for table

func (*Store) DeleteIndex added in v0.20.15

func (a *Store) DeleteIndex(ctx context.Context, resourceType string, indexName string) error

DeleteIndex delete single index for table

func (*Store) Get

func (a *Store) Get(ctx context.Context, resourceType string, opt *StoreGetOption) ([]operator.M, error)

Get get something from db according to request

func (*Store) GetDB

func (a *Store) GetDB() drivers.DB

GetDB return db interface

func (*Store) GetIndex added in v0.20.15

func (a *Store) GetIndex(ctx context.Context, resourceType string) (*drivers.Index, error)

GetIndex get indexes of table

func (*Store) Put

func (a *Store) Put(ctx context.Context, resourceType string, data operator.M, opt *StorePutOption) error

Put put something into db according to request

func (*Store) Remove

func (a *Store) Remove(ctx context.Context, resourceType string, opt *StoreRemoveOption) error

Remove remove something from db according to request

func (*Store) SetSoftDeletion added in v0.20.14

func (a *Store) SetSoftDeletion(flag bool)

SetSoftDeletion set store to do soft delet

func (*Store) Watch

func (a *Store) Watch(ctx context.Context, resourceType string, opt *StoreWatchOption) (chan *Event, error)

Watch watch some resource type

type StoreGetOption

type StoreGetOption struct {
	Fields         []string
	Sort           map[string]int
	Cond           *operator.Condition
	Offset         int64
	Limit          int64
	IsAllDocuments bool
}

StoreGetOption option for get action

type StorePutOption

type StorePutOption struct {
	UniqueKey     []string
	Cond          *operator.Condition
	CreateTimeKey string
	UpdateTimeKey string
}

StorePutOption option for put action

type StoreRemoveOption

type StoreRemoveOption struct {
	Cond *operator.Condition
	// IgnoreNotFound if return err when data not found
	IgnoreNotFound bool
}

StoreRemoveOption option for remove action

type StoreWatchOption

type StoreWatchOption struct {
	Cond      operator.M
	SelfOnly  bool
	MaxEvents uint
	Timeout   time.Duration
	MustDiff  string
}

StoreWatchOption option for watch action

type WatchServer

type WatchServer struct {
	Writer func(resp *restful.Response, event *Event) bool
	// contains filtered or unexported fields
}

WatchServer the server side handler in a watch action.

func NewWatchServer

func NewWatchServer(wopt *WatchServerOption) (*WatchServer, error)

NewWatchServer create default json formate watchServer

func (*WatchServer) Go

func (ws *WatchServer) Go(ctx context.Context)

Go running watchServer

type WatchServerOption

type WatchServerOption struct {
	Store     *Store
	TableName string
	Cond      operator.M
	Req       *restful.Request
	Resp      *restful.Response
}

WatchServerOption options for watch server

Jump to

Keyboard shortcuts

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