github.com/s7techlab/cckit@v0.10.5/extensions/owner/modifier.go (about)

     1  package owner
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/pkg/errors"
     7  
     8  	"github.com/s7techlab/cckit/router"
     9  )
    10  
    11  var (
    12  	// ErrOwnerOnly error occurs when trying to invoke chaincode func  protected by onlyOwner middleware (modifier)
    13  	ErrOwnerOnly = errors.New(`owner only`)
    14  )
    15  
    16  // Only allow access from chain code owner
    17  func Only(next router.HandlerFunc, _ ...int) router.HandlerFunc {
    18  	return func(c router.Context) (interface{}, error) {
    19  		err := IsTxCreator(c)
    20  		if err == nil {
    21  			return next(c)
    22  		}
    23  		return nil, fmt.Errorf(`%s: %w`, err, ErrOwnerOnly)
    24  	}
    25  }