chain

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package chain convert the method of nested fields in structure to call chain function.

Copyright 2020 HenryLee. All Rights Reserved.

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 ErrEmpty = errors.New("no method chain found")

ErrEmpty no method error

Functions

This section is empty.

Types

type Args

type Args interface {
	Init(NestedStruct) error
	Arg(recvType reflect.Type, idx int, in reflect.Type) (reflect.Value, error)
}

Args create input argument

type Base

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

func (*Base) Abort

func (b *Base) Abort(err error)

Abort prevents pending methods from being called. NOTE:

That this will not stop the execution chain.

func (*Base) IsAborted

func (b *Base) IsAborted() bool

IsAborted returns true if the current execution chain was aborted.

func (*Base) Next

func (b *Base) Next()

Next executes the pending methods in the chain inside the calling method.

type FactoryFunc added in v0.1.0

type FactoryFunc func() NestedStruct

FactoryFunc creates a new NestedStruct object

type FindFunc

type FindFunc func(level int, methods []reflect.Method) (*reflect.Method, error)

FindFunc find the first matched method

func FindName

func FindName(methodName string) FindFunc

FindName finds the first method encountered that matches the methodName

type Func

type Func func(Args) error

Func function to execute method chain

func New

func New(obj NestedStruct, find FindFunc) (Func, error)

New creates a chained execution function. NOTE:

The method of specifying the name cannot have a return value

func NewFrom added in v0.1.0

func NewFrom(factory FactoryFunc, find FindFunc) (Func, error)

NewFrom creates a chained execution function from NestedStruct factory. NOTE:

The method of specifying the name cannot have a return value

type NestedStruct

type NestedStruct interface {
	Next()
	Abort(error)
	IsAborted() bool
	// contains filtered or unexported methods
}

NestedStruct nested structure carrying method chain

Jump to

Keyboard shortcuts

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