types

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const AppContextKey = constants.BINARY_NAME + "-app-context"

AppContextKey is the key in the context.Context which holds the application context.

Variables

View Source
var ErrUpstreamRpcReturnedError = errors.New("upstream RPC returned error")

ErrUpstreamRpcReturnedError is the error when the upstream RPC returned error

Functions

func IsErrUpstreamRpcReturnedError

func IsErrUpstreamRpcReturnedError(err error) bool

IsErrUpstreamRpcReturnedError returns true if the error is built from upstream RPC response error, when error code is not zero.

func ParseJsonRpcResponse

func ParseJsonRpcResponse[T any](bz []byte) (any, error)

func WrapAppContext

func WrapAppContext(ctx Context) context.Context

Types

type Context

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

func NewContext

func NewContext(operationUserInfo *OperationUserInfo) Context

func UnwrapAppContext

func UnwrapAppContext(ctx context.Context) Context

func (Context) Deadline

func (c Context) Deadline() (deadline time.Time, ok bool)

func (Context) Done

func (c Context) Done() <-chan struct{}

func (Context) Err

func (c Context) Err() error

func (Context) GetOperationUserInfo

func (c Context) GetOperationUserInfo() *OperationUserInfo

func (Context) GetWorkingUserInfo

func (c Context) GetWorkingUserInfo() *UserInfo

func (Context) Value

func (c Context) Value(key any) any

func (Context) WithContext

func (c Context) WithContext(ctx context.Context) Context

func (Context) WithWorkingUserInfo

func (c Context) WithWorkingUserInfo(workingUserInfo *UserInfo) Context

type ContextKey

type ContextKey string

ContextKey defines a type alias for a stdlib Context key.

type JsonRpcQueryBuilder

type JsonRpcQueryBuilder interface {
	String() string
}

func NewJsonRpcQueryBuilder

func NewJsonRpcQueryBuilder(
	method string,
	params ...JsonRpcQueryParam,
) JsonRpcQueryBuilder

type JsonRpcQueryParam

type JsonRpcQueryParam interface {
	// IsArray returns true if the param is array formed
	IsArray() bool

	// String returns string of the param
	String() string
}

func NewJsonRpcBoolQueryParam

func NewJsonRpcBoolQueryParam(value bool) JsonRpcQueryParam

func NewJsonRpcInt64QueryParam

func NewJsonRpcInt64QueryParam(num int64) JsonRpcQueryParam

func NewJsonRpcIntQueryParam

func NewJsonRpcIntQueryParam(num int) JsonRpcQueryParam

func NewJsonRpcRawQueryParam

func NewJsonRpcRawQueryParam(rawStr string) JsonRpcQueryParam

func NewJsonRpcStringArrayQueryParam

func NewJsonRpcStringArrayQueryParam(strArr ...string) (JsonRpcQueryParam, error)

func NewJsonRpcStringQueryParam

func NewJsonRpcStringQueryParam(str string) (JsonRpcQueryParam, error)

type OperationUserInfo

type OperationUserInfo struct {
	EffectiveUserInfo *UserInfo
	RealUserInfo      *UserInfo
	// IsSameUser indicate that operation user is the same as real user
	IsSameUser bool
	// IsSuperUser indicate that operation user is "root" or a user that belong to a super-user group
	IsSuperUser bool
	// OperatingAsSuperUser indicates that operation user is "root" or a user runs command with "sudo"
	OperatingAsSuperUser bool
}

func (*OperationUserInfo) GetDefaultWorkingUser

func (o *OperationUserInfo) GetDefaultWorkingUser() *UserInfo

GetDefaultWorkingUser returns:

- Effective user if is not super-user and not operating as super-user

- Real user otherwise

func (*OperationUserInfo) RequireOperatingAsNonSuperUser

func (o *OperationUserInfo) RequireOperatingAsNonSuperUser()

func (*OperationUserInfo) RequireOperatingAsSuperUser

func (o *OperationUserInfo) RequireOperatingAsSuperUser()

func (*OperationUserInfo) RequireSuperUser

func (o *OperationUserInfo) RequireSuperUser()

type UserInfo

type UserInfo struct {
	UserId   int
	Username string
	HomeDir  string
	User     *user.User
	// IsSuperUser indicate that the user is "root" or a user that belong to a super-user group
	IsSuperUser bool
}

Jump to

Keyboard shortcuts

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