storage_events

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 7 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Storage Event

一、这是什么

把Storage和events结合,为Storage增加可观测性和安全执行功能。

二、安装依赖

go get -u github.com/storage-lock/go-storage-events

三、组件介绍

WithEventSafeExecutor

为Storage增加可观测性和安全执行功能

四、使用示例

package main

import (
	"context"
	"fmt"
	"github.com/golang-infrastructure/go-iterator"
	"github.com/storage-lock/go-events"
	"github.com/storage-lock/go-storage"
	storage_events "github.com/storage-lock/go-storage-events"
	"time"
)

type FooStorage struct {
}

var _ storage.Storage = &FooStorage{}

func (x *FooStorage) GetName() string {
	//TODO implement me
	panic("implement me")
}

func (x *FooStorage) Init(ctx context.Context) error {
	//TODO implement me
	panic("implement me")
}

func (x *FooStorage) UpdateWithVersion(ctx context.Context, lockId string, exceptedVersion, newVersion storage.Version, lockInformation *storage.LockInformation) error {
	//TODO implement me
	panic("implement me")
}

func (x *FooStorage) CreateWithVersion(ctx context.Context, lockId string, version storage.Version, lockInformation *storage.LockInformation) error {
	//TODO implement me
	panic("implement me")
}

func (x *FooStorage) DeleteWithVersion(ctx context.Context, lockId string, exceptedVersion storage.Version, lockInformation *storage.LockInformation) error {
	//TODO implement me
	panic("implement me")
}

func (x *FooStorage) Get(ctx context.Context, lockId string) (string, error) {
	//TODO implement me
	panic("implement me")
}

func (x *FooStorage) GetTime(ctx context.Context) (time.Time, error) {
	//TODO implement me
	panic("implement me")
}

func (x *FooStorage) Close(ctx context.Context) error {
	//TODO implement me
	panic("implement me")
}

func (x *FooStorage) List(ctx context.Context) (iterator.Iterator[*storage.LockInformation], error) {
	//TODO implement me
	panic("implement me")
}

func main() {
	storage := &FooStorage{}
	executor := storage_events.NewWithEventSafeExecutor(storage)

	event := events.NewEvent("foo").AddListeners(events.NewListenerWrapper("", func(ctx context.Context, e *events.Event) {
		fmt.Print(e.ToJsonString())
	}))
	getTime, err := executor.GetTime(context.Background(), event)
	if err != nil {
		panic(err)
	}
	fmt.Println(getTime)
	// Output:
	// {"id":"storage-lock-event-eb8bffdcbf69414bb34719bfbda0147c","root_id":"storage-lock-event-eb8bffdcbf69414bb34719bfbda0147c","parent_id":"","lock_id":"foo","owner_id":"","storage_name":"","start_time":"2023-08-07T01:45:13.2932725+08:00","end_time":"2023-08-07T01:45:13.2932725+08:00","event_type":0,"actions":[{"start_time":"2023-08-07T01:45:13.293272 5+08:00","end_time":"2023-08-07T01:45:13.2932725+08:00","name":"Storage.GetTime","err":{},"payload_map":{"time":"0001-01-01T00:00:00Z"}}],"watch_dog_id":"","lock_information":null,"err":null}
	//
	// panic: implement me goroutine 1 [running]:
	// main.main()
	//     D:/workspace/go-storage-events/examples/main.go:72 +0x1c8
}

Documentation

Index

Constants

View Source
const (
	ActionStorageGetName = "Storage.GetName"

	ActionStorageInit        = "Storage.Init"
	ActionStorageInitSuccess = "Storage.Init.Success"
	ActionStorageInitError   = "Storage.Init.Error"

	ActionStorageUpdateWithVersion        = "Storage.UpdateWithVersion"
	ActionStorageUpdateWithVersionSuccess = "Storage.UpdateWithVersion.Success"
	ActionStorageUpdateWithVersionError   = "Storage.UpdateWithVersion.Error"
	ActionStorageUpdateWithVersionMiss    = "Storage.UpdateWithVersion.Miss"

	ActionStorageCreateWithVersion        = "Storage.CreateWithVersion"
	ActionStorageCreateWithVersionSuccess = "Storage.CreateWithVersion.Success"
	ActionStorageCreateWithVersionError   = "Storage.CreateWithVersion.Error"
	ActionStorageCreateWithVersionMiss    = "Storage.CreateWithVersion.Miss"

	ActionStorageDeleteWithVersion        = "Storage.DeleteWithVersion"
	ActionStorageDeleteWithVersionSuccess = "Storage.DeleteWithVersion.Success"
	ActionStorageDeleteWithVersionError   = "Storage.DeleteWithVersion.Error"
	ActionStorageDeleteWithVersionMiss    = "Storage.DeleteWithVersion.Miss"

	ActionStorageGetTime        = "Storage.GetTime"
	ActionStorageGetTimeSuccess = "Storage.GetTime.Success"
	ActionStorageGetTimeError   = "Storage.GetTime.Error"

	ActionStorageGet        = "Storage.Get"
	ActionStorageGetSuccess = "Storage.Get.Success"
	ActionStorageGetError   = "Storage.Get.Error"

	ActionStorageClose        = "Storage.Close"
	ActionStorageCloseSuccess = "Storage.Close.Success"
	ActionStorageCloseError   = "Storage.Close.Error"

	ActionStorageList        = "Storage.List"
	ActionStorageListSuccess = "Storage.List.Success"
	ActionStorageListError   = "Storage.List.Error"
)

用于统计Storage上的方法调用行为

View Source
const (
	PayloadName                      = "name"
	PayloadIterator                  = "iterator"
	PayloadTime                      = "time"
	PayloadLockInformationJsonString = "lockInformationJsonString"
	PayloadLockId                    = "lockId"
	PayloadLockInformation           = "lockInformation"
	PayloadVersion                   = "version"
	PayloadNewVersion                = "newVersion"
	PayloadExceptedVersion           = "exceptedVersion"
)

action上的payload的名称,用于方便跟处理的时候统一

Variables

This section is empty.

Functions

This section is empty.

Types

type WithEventSafeExecutor

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

WithEventSafeExecutor 带事件观测和recover的Storage执行器

func NewWithEventSafeExecutor

func NewWithEventSafeExecutor(storage storage.Storage) *WithEventSafeExecutor

NewWithEventSafeExecutor 从给定的Storage创建一个执行器,后面就拿着这个执行器操作而不直接操作Storage了

func (*WithEventSafeExecutor) Close

func (x *WithEventSafeExecutor) Close(ctx context.Context, e *events.Event) (err error)

func (*WithEventSafeExecutor) CreateWithVersion added in v0.0.2

func (x *WithEventSafeExecutor) CreateWithVersion(ctx context.Context, e *events.Event, lockId string, version storage.Version, lockInformation *storage.LockInformation) (err error)

func (*WithEventSafeExecutor) DeleteWithVersion

func (x *WithEventSafeExecutor) DeleteWithVersion(ctx context.Context, e *events.Event, lockId string, exceptedVersion storage.Version, lockInformation *storage.LockInformation) (err error)

func (*WithEventSafeExecutor) Get

func (x *WithEventSafeExecutor) Get(ctx context.Context, e *events.Event, lockId string) (lockInformationJsonString string, err error)

func (*WithEventSafeExecutor) GetName

func (x *WithEventSafeExecutor) GetName(e *events.Event) (name string, err error)

func (*WithEventSafeExecutor) GetTime

func (x *WithEventSafeExecutor) GetTime(ctx context.Context, e *events.Event) (time time.Time, err error)

func (*WithEventSafeExecutor) Init

func (x *WithEventSafeExecutor) Init(ctx context.Context, e *events.Event) (err error)

func (*WithEventSafeExecutor) List

func (*WithEventSafeExecutor) UpdateWithVersion

func (x *WithEventSafeExecutor) UpdateWithVersion(ctx context.Context, e *events.Event, lockId string, exceptedVersion, newVersion storage.Version, lockInformation *storage.LockInformation) (err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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