utils

package
v0.0.0-...-94fc2ed Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2023 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Copyright 2021 Layotto Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2021 Layotto Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2021 Layotto Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2021 Layotto Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2021 Layotto Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2021 Layotto Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2021 Layotto Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var (
	Db *sql.DB
)
View Source
var (
	ErrNotInitClient = errors.New("oss client not init")
)

Functions

func GetMiliTimestamp

func GetMiliTimestamp(i int64) int64

func GetReadConcrenObject

func GetReadConcrenObject(cn string) (*readconcern.ReadConcern, error)

func GetWriteConcernObject

func GetWriteConcernObject(cn string) (*writeconcern.WriteConcern, error)

func NewClusterRedisClient

func NewClusterRedisClient(m RedisClusterMetadata) []*redis.Client

func NewEtcdClient

func NewEtcdClient(meta EtcdMetadata) (*clientv3.Client, error)

func NewMySQLClient

func NewMySQLClient(meta MySQLMetadata) error

func NewRedisClient

func NewRedisClient(m RedisMetadata) *redis.Client

Types

type ConnectionFactory

type ConnectionFactory interface {
	NewConnection(expire time.Duration, meta ZookeeperMetadata) (ZKConnection, error)
}

type ConnectionFactoryImpl

type ConnectionFactoryImpl struct {
}

func (*ConnectionFactoryImpl) NewConnection

func (c *ConnectionFactoryImpl) NewConnection(expire time.Duration, meta ZookeeperMetadata) (ZKConnection, error)

type ConsulClient

type ConsulClient interface {
	Session() *api.Session
}

type ConsulKV

type ConsulKV interface {
	Acquire(p *api.KVPair, q *api.WriteOptions) (bool, *api.WriteMeta, error)
	Release(p *api.KVPair, q *api.WriteOptions) (bool, *api.WriteMeta, error)
}

type ConsulMetadata

type ConsulMetadata struct {
	Address  string
	Scheme   string
	Username string
	Password string
}

func ParseConsulMetadata

func ParseConsulMetadata(meta lock.Metadata) (ConsulMetadata, error)

type EtcdMetadata

type EtcdMetadata struct {
	KeyPrefix   string
	DialTimeout int
	Endpoints   []string
	Username    string
	Password    string

	TlsCa      string
	TlsCert    string
	TlsCertKey string
}

func ParseEtcdMetadata

func ParseEtcdMetadata(properties map[string]string) (EtcdMetadata, error)

type Item

type Item struct {
	Key   string      `bson:"_id"`
	Value interface{} `bson:"value"`
	Etag  string      `bson:"_etag"`
}

Item is Mongodb document wrapper.

type MongoClient

type MongoClient interface {
	StartSession(opts ...*options.SessionOptions) (mongo.Session, error)
	Ping(ctx context.Context, rp *readpref.ReadPref) error
	Database(name string, opts ...*options.DatabaseOptions) *mongo.Database
	Disconnect(ctx context.Context) error
}

type MongoCollection

type MongoCollection interface {
	FindOne(ctx context.Context, filter interface{}, opts ...*options.FindOneOptions) *mongo.SingleResult
	InsertOne(ctx context.Context, document interface{}, opts ...*options.InsertOneOptions) (*mongo.InsertOneResult, error)
	DeleteOne(ctx context.Context, filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)
	Find(ctx context.Context, filter interface{}, opts ...*options.FindOptions) (*mongo.Cursor, error)
	Indexes() mongo.IndexView
	UpdateOne(ctx context.Context, filter interface{}, update interface{},
		opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
	FindOneAndUpdate(ctx context.Context, filter interface{},
		update interface{}, opts ...*options.FindOneAndUpdateOptions) *mongo.SingleResult
}

type MongoFactory

type MongoFactory interface {
	NewMongoClient(m MongoMetadata) (MongoClient, error)
	NewMongoCollection(m *mongo.Database, collectionName string, opts *options.CollectionOptions) MongoCollection
	NewSingleResult(sr *mongo.SingleResult) MongoSingleResult
}

type MongoFactoryImpl

type MongoFactoryImpl struct{}

func (*MongoFactoryImpl) NewMongoClient

func (c *MongoFactoryImpl) NewMongoClient(m MongoMetadata) (MongoClient, error)

func (*MongoFactoryImpl) NewMongoCollection

func (c *MongoFactoryImpl) NewMongoCollection(m *mongo.Database, collectionName string, opts *options.CollectionOptions) MongoCollection

func (*MongoFactoryImpl) NewSingleResult

func (c *MongoFactoryImpl) NewSingleResult(sr *mongo.SingleResult) MongoSingleResult

type MongoMetadata

type MongoMetadata struct {
	Host             string
	Username         string
	Password         string
	DatabaseName     string
	CollectionName   string
	Server           string
	Params           string
	WriteConcern     string
	ReadConcern      string
	OperationTimeout time.Duration
}

func ParseMongoMetadata

func ParseMongoMetadata(properties map[string]string) (MongoMetadata, error)

type MongoSession

type MongoSession interface {
	AbortTransaction(context.Context) error
	CommitTransaction(context.Context) error
	WithTransaction(ctx context.Context, fn func(sessCtx mongo.SessionContext) (interface{}, error),
		opts ...*options.TransactionOptions) (interface{}, error)
	EndSession(context.Context)
}

type MongoSingleResult

type MongoSingleResult interface {
	Decode(v interface{}) error
	Err() error
	DecodeBytes() (bson.Raw, error)
}

type MySQLMetadata

type MySQLMetadata struct {
	TableName    string
	DataBaseName string
	UserName     string
	Password     string
	MysqlUrl     string
	Db           *sql.DB
}

func ParseMySQLMetadata

func ParseMySQLMetadata(properties map[string]string) (MySQLMetadata, error)

type OssMetadata

type OssMetadata struct {
	Endpoint        string `json:"endpoint"`
	AccessKeyID     string `json:"accessKeyID"`
	AccessKeySecret string `json:"accessKeySecret"`
	Region          string `json:"region"`
}

OssMetadata wraps the configuration of oss implementation

type RedisClusterMetadata

type RedisClusterMetadata struct {
	Hosts           []string
	Concurrency     int
	Password        string
	MaxRetries      int
	MaxRetryBackoff time.Duration
	EnableTLS       bool
	DB              int
}

func ParseRedisClusterMetadata

func ParseRedisClusterMetadata(properties map[string]string) (RedisClusterMetadata, error)

type RedisMetadata

type RedisMetadata struct {
	Host            string
	Password        string
	MaxRetries      int
	MaxRetryBackoff time.Duration
	EnableTLS       bool
	DB              int
}

func ParseRedisMetadata

func ParseRedisMetadata(properties map[string]string) (RedisMetadata, error)

type SessionFactory

type SessionFactory interface {
	Create(se *api.SessionEntry, q *api.WriteOptions) (string, *api.WriteMeta, error)
	Destroy(id string, q *api.WriteOptions) (*api.WriteMeta, error)
}

type ZKConnection

type ZKConnection interface {
	Get(path string) ([]byte, *zk.Stat, error)
	Set(path string, data []byte, version int32) (*zk.Stat, error)
	Delete(path string, version int32) error
	Create(path string, data []byte, flags int32, acl []zk.ACL) (string, error)
	Close()
}

type ZookeeperMetadata

type ZookeeperMetadata struct {
	Hosts          []string
	Password       string
	SessionTimeout time.Duration
	LogInfo        bool
}

func ParseZookeeperMetadata

func ParseZookeeperMetadata(properties map[string]string) (ZookeeperMetadata, error)

Jump to

Keyboard shortcuts

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