github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/types/context.go (about)

     1  package types
     2  
     3  import (
     4  	"context"
     5  
     6  	"github.com/machinefi/w3bstream/pkg/depends/conf/filesystem"
     7  	"github.com/machinefi/w3bstream/pkg/depends/conf/log"
     8  	"github.com/machinefi/w3bstream/pkg/depends/conf/mqtt"
     9  	"github.com/machinefi/w3bstream/pkg/depends/conf/redis"
    10  	"github.com/machinefi/w3bstream/pkg/depends/kit/httptransport/client"
    11  	"github.com/machinefi/w3bstream/pkg/depends/kit/sqlx"
    12  	"github.com/machinefi/w3bstream/pkg/depends/x/contextx"
    13  	"github.com/machinefi/w3bstream/pkg/depends/x/misc/must"
    14  	"github.com/machinefi/w3bstream/pkg/models"
    15  	optypes "github.com/machinefi/w3bstream/pkg/modules/operator/pool/types"
    16  	wasmapi "github.com/machinefi/w3bstream/pkg/modules/vm/wasmapi/types"
    17  )
    18  
    19  // global contexts
    20  type (
    21  	// CtxMgrDBExecutor type sqlx.DBExecutor for global manager server database
    22  	CtxMgrDBExecutor struct{}
    23  	// CtxMonitorDBExecutor type sqlx.DBExecutor for global monitor server database
    24  	CtxMonitorDBExecutor struct{}
    25  	// CtxLogger type log.Logger. service logger
    26  	CtxLogger struct{}
    27  	// CtxMqttBroker *mqtt.Broker. mqtt broker
    28  	CtxMqttBroker struct{}
    29  	// CtxRedisEndpoint type *redis.Redis. redis endpoint
    30  	CtxRedisEndpoint struct{}
    31  	// CtxUploadConfig type *UploadConfig. resource upload configuration
    32  	CtxUploadConfig struct{}
    33  	// CtxWhiteList type *EthAddressWhiteList global eth address white list
    34  	CtxEthAddressWhiteList struct{}
    35  	// CtxEthClient type *ETHClientConfig global eth chain endpoints
    36  	CtxEthClient struct{}
    37  	// CtxChainConfig type *ChainConfig global chain endpoints
    38  	CtxChainConfig struct{}
    39  	// CtxFileSystemOp type filesystem.FileSystemOp describe resource storing operation type
    40  	CtxFileSystemOp struct{}
    41  	// CtxProxyClient type *client.Client http client for forwarding mqtt event
    42  	CtxProxyClient struct{}
    43  	// CtxWasmDBConfig type *WasmDBConfig wasm database config
    44  	CtxWasmDBConfig struct{}
    45  	// CtxRobotNotifierConfig type *RobotNotifierConfig for notify service level message to maintainers.
    46  	CtxRobotNotifierConfig struct{}
    47  	// CtxMetricsCenterConfig *MetricsCenterConfig for metrics
    48  	CtxMetricsCenterConfig struct{}
    49  	// CtxOperatorPool type *operator.Pool global operator memory pool
    50  	CtxOperatorPool struct{}
    51  	// CtxMaxWasmConsumeFuel global wasm consume fuel per invoking
    52  	CtxMaxWasmConsumeFuel struct{}
    53  	// CtxEnableTrafficLimit if enable traffic limit
    54  	CtxEnableTrafficLimit struct{}
    55  	// CtxProjectFilter global project filter
    56  	CtxProjectFilter struct{}
    57  )
    58  
    59  // model contexts
    60  type (
    61  	// CtxProject type *models.Project
    62  	CtxProject struct{}
    63  	// CtxApplet type *models.Applet
    64  	CtxApplet struct{}
    65  	// CtxResource type *models.Resource
    66  	CtxResource struct{}
    67  	// CtxInstance type *models.Instance
    68  	CtxInstance struct{}
    69  	// CtxStrategy type *models.Strategy
    70  	CtxStrategy struct{}
    71  	// CtxPublisher type *models.Publisher
    72  	CtxPublisher struct{}
    73  	// CtxCronJob type *models.CronJob
    74  	CtxCronJob struct{}
    75  	// CtxOperator type *models.Operator
    76  	CtxOperator struct{}
    77  	// CtxOperators type []models.Operator filtered operators
    78  	CtxOperators struct{}
    79  	// CtxProjectOperator type *models.ProjectOperator
    80  	CtxProjectOperator struct{}
    81  	// CtxContractLog type *models.ContractLog
    82  	CtxContractLog struct{}
    83  	// CtxChainHeight type *models.ChainHeight
    84  	CtxChainHeight struct{}
    85  	// CtxChainTx type *models.ChainTx
    86  	CtxChainTx struct{}
    87  	// CtxAccount type *models.Account
    88  	CtxAccount struct{}
    89  	// CtxResourceOwnership type *models.ResourceOwnership
    90  	CtxResourceOwnership struct{}
    91  	// CtxTrafficLimit type *models.TrafficLimit
    92  	CtxTrafficLimit struct{}
    93  )
    94  type (
    95  	// CtxStrategyResults type []*StrategyResult event strategies
    96  	CtxStrategyResults struct{} // CtxStrategyResults
    97  	// CtxEventID type string. current event id
    98  	CtxEventID struct{}
    99  	// CtxWasmApiServer type wasmapi/types.Server wasm global async server TODO move to wasm context package
   100  	CtxWasmApiServer struct{}
   101  )
   102  
   103  func WithStrategyResults(ctx context.Context, v []*StrategyResult) context.Context {
   104  	return contextx.WithValue(ctx, CtxStrategyResults{}, v)
   105  }
   106  
   107  func WithStrategyResultsContext(v []*StrategyResult) contextx.WithContext {
   108  	return func(ctx context.Context) context.Context {
   109  		return contextx.WithValue(ctx, CtxStrategyResults{}, v)
   110  	}
   111  }
   112  
   113  func StrategyResultsFromContext(ctx context.Context) ([]*StrategyResult, bool) {
   114  	v, ok := ctx.Value(CtxStrategyResults{}).([]*StrategyResult)
   115  	return v, ok
   116  }
   117  
   118  func MustStrategyResultsFromContext(ctx context.Context) []*StrategyResult {
   119  	v, ok := StrategyResultsFromContext(ctx)
   120  	must.BeTrue(ok)
   121  	return v
   122  }
   123  
   124  func WithAccount(ctx context.Context, v *models.Account) context.Context {
   125  	return contextx.WithValue(ctx, CtxAccount{}, v)
   126  }
   127  
   128  func WithAccountContext(v *models.Account) contextx.WithContext {
   129  	return func(ctx context.Context) context.Context {
   130  		return contextx.WithValue(ctx, CtxAccount{}, v)
   131  	}
   132  }
   133  
   134  func AccountFromContext(ctx context.Context) (*models.Account, bool) {
   135  	v, ok := ctx.Value(CtxAccount{}).(*models.Account)
   136  	return v, ok
   137  }
   138  
   139  func MustAccountFromContext(ctx context.Context) *models.Account {
   140  	v, ok := AccountFromContext(ctx)
   141  	must.BeTrue(ok)
   142  	return v
   143  }
   144  
   145  func WithPublisher(ctx context.Context, v *models.Publisher) context.Context {
   146  	return contextx.WithValue(ctx, CtxPublisher{}, v)
   147  }
   148  
   149  func WithPublisherContext(v *models.Publisher) contextx.WithContext {
   150  	return func(ctx context.Context) context.Context {
   151  		return contextx.WithValue(ctx, CtxPublisher{}, v)
   152  	}
   153  }
   154  
   155  func PublisherFromContext(ctx context.Context) (*models.Publisher, bool) {
   156  	v, ok := ctx.Value(CtxPublisher{}).(*models.Publisher)
   157  	return v, ok
   158  }
   159  
   160  func MustPublisherFromContext(ctx context.Context) *models.Publisher {
   161  	v, ok := PublisherFromContext(ctx)
   162  	must.BeTrue(ok)
   163  	return v
   164  }
   165  
   166  func WithCronJob(ctx context.Context, v *models.CronJob) context.Context {
   167  	return contextx.WithValue(ctx, CtxCronJob{}, v)
   168  }
   169  
   170  func WithCronJobContext(v *models.CronJob) contextx.WithContext {
   171  	return func(ctx context.Context) context.Context {
   172  		return contextx.WithValue(ctx, CtxCronJob{}, v)
   173  	}
   174  }
   175  
   176  func CronJobFromContext(ctx context.Context) (*models.CronJob, bool) {
   177  	v, ok := ctx.Value(CtxCronJob{}).(*models.CronJob)
   178  	return v, ok
   179  }
   180  
   181  func MustCronJobFromContext(ctx context.Context) *models.CronJob {
   182  	v, ok := CronJobFromContext(ctx)
   183  	must.BeTrue(ok)
   184  	return v
   185  }
   186  
   187  func WithOperator(ctx context.Context, v *models.Operator) context.Context {
   188  	return contextx.WithValue(ctx, CtxOperator{}, v)
   189  }
   190  
   191  func WithOperatorContext(v *models.Operator) contextx.WithContext {
   192  	return func(ctx context.Context) context.Context {
   193  		return contextx.WithValue(ctx, CtxOperator{}, v)
   194  	}
   195  }
   196  
   197  func OperatorFromContext(ctx context.Context) (*models.Operator, bool) {
   198  	v, ok := ctx.Value(CtxOperator{}).(*models.Operator)
   199  	return v, ok
   200  }
   201  
   202  func MustOperatorFromContext(ctx context.Context) *models.Operator {
   203  	v, ok := OperatorFromContext(ctx)
   204  	must.BeTrue(ok)
   205  	return v
   206  }
   207  
   208  func WithContractLog(ctx context.Context, v *models.ContractLog) context.Context {
   209  	return contextx.WithValue(ctx, CtxContractLog{}, v)
   210  }
   211  
   212  func WithContractLogContext(v *models.ContractLog) contextx.WithContext {
   213  	return func(ctx context.Context) context.Context {
   214  		return contextx.WithValue(ctx, CtxContractLog{}, v)
   215  	}
   216  }
   217  
   218  func ContractLogFromContext(ctx context.Context) (*models.ContractLog, bool) {
   219  	v, ok := ctx.Value(CtxContractLog{}).(*models.ContractLog)
   220  	return v, ok
   221  }
   222  
   223  func MustContractLogFromContext(ctx context.Context) *models.ContractLog {
   224  	v, ok := ContractLogFromContext(ctx)
   225  	must.BeTrue(ok)
   226  	return v
   227  }
   228  
   229  func WithChainHeight(ctx context.Context, v *models.ChainHeight) context.Context {
   230  	return contextx.WithValue(ctx, CtxChainHeight{}, v)
   231  }
   232  
   233  func WithChainHeightContext(v *models.ChainHeight) contextx.WithContext {
   234  	return func(ctx context.Context) context.Context {
   235  		return contextx.WithValue(ctx, CtxChainHeight{}, v)
   236  	}
   237  }
   238  
   239  func ChainHeightFromContext(ctx context.Context) (*models.ChainHeight, bool) {
   240  	v, ok := ctx.Value(CtxChainHeight{}).(*models.ChainHeight)
   241  	return v, ok
   242  }
   243  
   244  func MustChainHeightFromContext(ctx context.Context) *models.ChainHeight {
   245  	v, ok := ChainHeightFromContext(ctx)
   246  	must.BeTrue(ok)
   247  	return v
   248  }
   249  
   250  func WithChainTx(ctx context.Context, v *models.ChainTx) context.Context {
   251  	return contextx.WithValue(ctx, CtxChainTx{}, v)
   252  }
   253  
   254  func WithChainTxContext(v *models.ChainTx) contextx.WithContext {
   255  	return func(ctx context.Context) context.Context {
   256  		return contextx.WithValue(ctx, CtxChainTx{}, v)
   257  	}
   258  }
   259  
   260  func ChainTxFromContext(ctx context.Context) (*models.ChainTx, bool) {
   261  	v, ok := ctx.Value(CtxChainTx{}).(*models.ChainTx)
   262  	return v, ok
   263  }
   264  
   265  func MustChainTxFromContext(ctx context.Context) *models.ChainTx {
   266  	v, ok := ChainTxFromContext(ctx)
   267  	must.BeTrue(ok)
   268  	return v
   269  }
   270  
   271  func WithStrategy(ctx context.Context, v *models.Strategy) context.Context {
   272  	return contextx.WithValue(ctx, CtxStrategy{}, v)
   273  }
   274  
   275  func WithStrategyContext(v *models.Strategy) contextx.WithContext {
   276  	return func(ctx context.Context) context.Context {
   277  		return contextx.WithValue(ctx, CtxStrategy{}, v)
   278  	}
   279  }
   280  
   281  func StrategyFromContext(ctx context.Context) (*models.Strategy, bool) {
   282  	v, ok := ctx.Value(CtxStrategy{}).(*models.Strategy)
   283  	return v, ok
   284  }
   285  
   286  func MustStrategyFromContext(ctx context.Context) *models.Strategy {
   287  	v, ok := StrategyFromContext(ctx)
   288  	must.BeTrue(ok)
   289  	return v
   290  }
   291  
   292  func WithMgrDBExecutor(ctx context.Context, v sqlx.DBExecutor) context.Context {
   293  	return contextx.WithValue(ctx, CtxMgrDBExecutor{}, v)
   294  }
   295  
   296  func WithMgrDBExecutorContext(v sqlx.DBExecutor) contextx.WithContext {
   297  	return func(ctx context.Context) context.Context {
   298  		return contextx.WithValue(ctx, CtxMgrDBExecutor{}, v)
   299  	}
   300  }
   301  
   302  func MgrDBExecutorFromContext(ctx context.Context) (sqlx.DBExecutor, bool) {
   303  	v, ok := ctx.Value(CtxMgrDBExecutor{}).(sqlx.DBExecutor)
   304  	return v, ok
   305  }
   306  
   307  func MustMgrDBExecutorFromContext(ctx context.Context) sqlx.DBExecutor {
   308  	v, ok := MgrDBExecutorFromContext(ctx)
   309  	must.BeTrue(ok)
   310  	return v
   311  }
   312  
   313  func WithMonitorDBExecutor(ctx context.Context, v sqlx.DBExecutor) context.Context {
   314  	return contextx.WithValue(ctx, CtxMonitorDBExecutor{}, v)
   315  }
   316  
   317  func WithMonitorDBExecutorContext(v sqlx.DBExecutor) contextx.WithContext {
   318  	return func(ctx context.Context) context.Context {
   319  		return contextx.WithValue(ctx, CtxMonitorDBExecutor{}, v)
   320  	}
   321  }
   322  
   323  func MonitorDBExecutorFromContext(ctx context.Context) (sqlx.DBExecutor, bool) {
   324  	v, ok := ctx.Value(CtxMonitorDBExecutor{}).(sqlx.DBExecutor)
   325  	return v, ok
   326  }
   327  
   328  func MustMonitorDBExecutorFromContext(ctx context.Context) sqlx.DBExecutor {
   329  	v, ok := MonitorDBExecutorFromContext(ctx)
   330  	must.BeTrue(ok)
   331  	return v
   332  }
   333  
   334  func WithRedis(ctx context.Context, v *redis.Redis) context.Context {
   335  	return contextx.WithValue(ctx, CtxRedisEndpoint{}, v)
   336  }
   337  
   338  func WithRedisEndpointContext(v *redis.Redis) contextx.WithContext {
   339  	return func(ctx context.Context) context.Context {
   340  		return contextx.WithValue(ctx, CtxRedisEndpoint{}, v)
   341  	}
   342  }
   343  
   344  func RedisEndpointFromContext(ctx context.Context) (*redis.Redis, bool) {
   345  	v, ok := ctx.Value(CtxRedisEndpoint{}).(*redis.Redis)
   346  	return v, ok
   347  }
   348  
   349  func MustRedisEndpointFromContext(ctx context.Context) *redis.Redis {
   350  	v, ok := RedisEndpointFromContext(ctx)
   351  	must.BeTrue(ok)
   352  	return v
   353  }
   354  
   355  func WithLogger(ctx context.Context, v log.Logger) context.Context {
   356  	return contextx.WithValue(ctx, CtxLogger{}, v)
   357  }
   358  
   359  func WithLoggerContext(v log.Logger) contextx.WithContext {
   360  	return func(ctx context.Context) context.Context {
   361  		return contextx.WithValue(ctx, CtxLogger{}, v)
   362  	}
   363  }
   364  
   365  func LoggerFromContext(ctx context.Context) (log.Logger, bool) {
   366  	v, ok := ctx.Value(CtxLogger{}).(log.Logger)
   367  	return v, ok
   368  }
   369  
   370  func MustLoggerFromContext(ctx context.Context) log.Logger {
   371  	v, ok := LoggerFromContext(ctx)
   372  	must.BeTrue(ok)
   373  	return v
   374  }
   375  
   376  func WithMqttBroker(ctx context.Context, v *mqtt.Broker) context.Context {
   377  	return contextx.WithValue(ctx, CtxMqttBroker{}, v)
   378  }
   379  
   380  func WithMqttBrokerContext(v *mqtt.Broker) contextx.WithContext {
   381  	return func(ctx context.Context) context.Context {
   382  		return contextx.WithValue(ctx, CtxMqttBroker{}, v)
   383  	}
   384  }
   385  
   386  func MqttBrokerFromContext(ctx context.Context) (*mqtt.Broker, bool) {
   387  	v, ok := ctx.Value(CtxMqttBroker{}).(*mqtt.Broker)
   388  	return v, ok
   389  }
   390  
   391  func MustMqttBrokerFromContext(ctx context.Context) *mqtt.Broker {
   392  	v, ok := MqttBrokerFromContext(ctx)
   393  	must.BeTrue(ok)
   394  	return v
   395  }
   396  
   397  func WithProject(ctx context.Context, p *models.Project) context.Context {
   398  	_p := *p
   399  	return contextx.WithValue(ctx, CtxProject{}, &_p)
   400  }
   401  
   402  func WithProjectContext(p *models.Project) contextx.WithContext {
   403  	return func(ctx context.Context) context.Context {
   404  		return WithProject(ctx, p)
   405  	}
   406  }
   407  
   408  func ProjectFromContext(ctx context.Context) (*models.Project, bool) {
   409  	v, ok := ctx.Value(CtxProject{}).(*models.Project)
   410  	return v, ok
   411  }
   412  
   413  func MustProjectFromContext(ctx context.Context) *models.Project {
   414  	v, ok := ProjectFromContext(ctx)
   415  	must.BeTrue(ok)
   416  	return v
   417  }
   418  
   419  func WithApplet(ctx context.Context, a *models.Applet) context.Context {
   420  	_a := *a
   421  	return contextx.WithValue(ctx, CtxApplet{}, &_a)
   422  }
   423  
   424  func WithAppletContext(a *models.Applet) contextx.WithContext {
   425  	return func(ctx context.Context) context.Context {
   426  		return WithApplet(ctx, a)
   427  	}
   428  }
   429  
   430  func AppletFromContext(ctx context.Context) (*models.Applet, bool) {
   431  	v, ok := ctx.Value(CtxApplet{}).(*models.Applet)
   432  	return v, ok
   433  }
   434  
   435  func MustAppletFromContext(ctx context.Context) *models.Applet {
   436  	v, ok := AppletFromContext(ctx)
   437  	must.BeTrue(ok)
   438  	return v
   439  }
   440  
   441  func WithResource(ctx context.Context, r *models.Resource) context.Context {
   442  	_r := *r
   443  	return contextx.WithValue(ctx, CtxResource{}, &_r)
   444  }
   445  
   446  func WithResourceContext(r *models.Resource) contextx.WithContext {
   447  	return func(ctx context.Context) context.Context {
   448  		return WithResource(ctx, r)
   449  	}
   450  }
   451  
   452  func ResourceFromContext(ctx context.Context) (*models.Resource, bool) {
   453  	v, ok := ctx.Value(CtxResource{}).(*models.Resource)
   454  	return v, ok
   455  }
   456  
   457  func MustResourceFromContext(ctx context.Context) *models.Resource {
   458  	v, ok := ResourceFromContext(ctx)
   459  	must.BeTrue(ok)
   460  	return v
   461  }
   462  
   463  func WithInstance(ctx context.Context, i *models.Instance) context.Context {
   464  	_i := *i
   465  	return contextx.WithValue(ctx, CtxInstance{}, &_i)
   466  }
   467  
   468  func WithInstanceContext(i *models.Instance) contextx.WithContext {
   469  	return func(ctx context.Context) context.Context {
   470  		return WithInstance(ctx, i)
   471  	}
   472  }
   473  
   474  func InstanceFromContext(ctx context.Context) (*models.Instance, bool) {
   475  	v, ok := ctx.Value(CtxInstance{}).(*models.Instance)
   476  	return v, ok
   477  }
   478  
   479  func MustInstanceFromContext(ctx context.Context) *models.Instance {
   480  	v, ok := InstanceFromContext(ctx)
   481  	must.BeTrue(ok)
   482  	return v
   483  }
   484  
   485  func WithETHClientConfig(ctx context.Context, v *ETHClientConfig) context.Context {
   486  	return contextx.WithValue(ctx, CtxEthClient{}, v)
   487  }
   488  
   489  func WithETHClientConfigContext(v *ETHClientConfig) contextx.WithContext {
   490  	return func(ctx context.Context) context.Context {
   491  		return contextx.WithValue(ctx, CtxEthClient{}, v)
   492  	}
   493  }
   494  
   495  func ETHClientConfigFromContext(ctx context.Context) (*ETHClientConfig, bool) {
   496  	v, ok := ctx.Value(CtxEthClient{}).(*ETHClientConfig)
   497  	return v, ok
   498  }
   499  
   500  func MustETHClientConfigFromContext(ctx context.Context) *ETHClientConfig {
   501  	v, ok := ETHClientConfigFromContext(ctx)
   502  	must.BeTrue(ok)
   503  	return v
   504  }
   505  
   506  func WithChainConfig(ctx context.Context, v *ChainConfig) context.Context {
   507  	return contextx.WithValue(ctx, CtxChainConfig{}, v)
   508  }
   509  
   510  func WithChainConfigContext(v *ChainConfig) contextx.WithContext {
   511  	return func(ctx context.Context) context.Context {
   512  		return contextx.WithValue(ctx, CtxChainConfig{}, v)
   513  	}
   514  }
   515  
   516  func ChainConfigFromContext(ctx context.Context) (*ChainConfig, bool) {
   517  	v, ok := ctx.Value(CtxChainConfig{}).(*ChainConfig)
   518  	return v, ok
   519  }
   520  
   521  func MustChainConfigFromContext(ctx context.Context) *ChainConfig {
   522  	v, ok := ChainConfigFromContext(ctx)
   523  	must.BeTrue(ok)
   524  	return v
   525  }
   526  
   527  func WithEthAddressWhiteList(ctx context.Context, v *EthAddressWhiteList) context.Context {
   528  	return contextx.WithValue(ctx, CtxEthAddressWhiteList{}, v)
   529  }
   530  
   531  func WithEthAddressWhiteListContext(v *EthAddressWhiteList) contextx.WithContext {
   532  	return func(ctx context.Context) context.Context {
   533  		return contextx.WithValue(ctx, CtxEthAddressWhiteList{}, v)
   534  	}
   535  }
   536  
   537  func EthAddressWhiteListFromContext(ctx context.Context) (*EthAddressWhiteList, bool) {
   538  	v, ok := ctx.Value(CtxEthAddressWhiteList{}).(*EthAddressWhiteList)
   539  	return v, ok
   540  }
   541  
   542  func MustEthAddressWhiteListFromContext(ctx context.Context) *EthAddressWhiteList {
   543  	v, ok := EthAddressWhiteListFromContext(ctx)
   544  	must.BeTrue(ok)
   545  	return v
   546  }
   547  
   548  func WithFileSystemOp(ctx context.Context, v filesystem.FileSystemOp) context.Context {
   549  	return contextx.WithValue(ctx, CtxFileSystemOp{}, v)
   550  }
   551  
   552  func WithFileSystemOpContext(v filesystem.FileSystemOp) contextx.WithContext {
   553  	return func(ctx context.Context) context.Context {
   554  		return contextx.WithValue(ctx, CtxFileSystemOp{}, v)
   555  	}
   556  }
   557  
   558  func FileSystemOpFromContext(ctx context.Context) (filesystem.FileSystemOp, bool) {
   559  	v, ok := ctx.Value(CtxFileSystemOp{}).(filesystem.FileSystemOp)
   560  	return v, ok
   561  }
   562  
   563  func MustFileSystemOpFromContext(ctx context.Context) filesystem.FileSystemOp {
   564  	v, ok := FileSystemOpFromContext(ctx)
   565  	must.BeTrue(ok)
   566  	return v
   567  }
   568  
   569  func WithProxyClient(ctx context.Context, v *client.Client) context.Context {
   570  	return contextx.WithValue(ctx, CtxProxyClient{}, v)
   571  }
   572  
   573  func WithProxyClientContext(v *client.Client) contextx.WithContext {
   574  	return func(ctx context.Context) context.Context {
   575  		return contextx.WithValue(ctx, CtxProxyClient{}, v)
   576  	}
   577  }
   578  
   579  func ProxyClientFromContext(ctx context.Context) (*client.Client, bool) {
   580  	v, ok := ctx.Value(CtxProxyClient{}).(*client.Client)
   581  	return v, ok
   582  }
   583  
   584  func MustProxyClientFromContext(ctx context.Context) *client.Client {
   585  	v, ok := ProxyClientFromContext(ctx)
   586  	must.BeTrue(ok)
   587  	return v
   588  }
   589  
   590  func WithResourceOwnership(ctx context.Context, o *models.ResourceOwnership) context.Context {
   591  	return contextx.WithValue(ctx, CtxResourceOwnership{}, o)
   592  }
   593  
   594  func WithResourceOwnershipContext(o *models.ResourceOwnership) contextx.WithContext {
   595  	return func(ctx context.Context) context.Context {
   596  		return contextx.WithValue(ctx, CtxResourceOwnership{}, o)
   597  	}
   598  }
   599  
   600  func ResourceOwnershipFromContext(ctx context.Context) (*models.ResourceOwnership, bool) {
   601  	v, ok := ctx.Value(CtxResourceOwnership{}).(*models.ResourceOwnership)
   602  	return v, ok
   603  }
   604  
   605  func MustResourceOwnershipFromContext(ctx context.Context) *models.ResourceOwnership {
   606  	v, ok := ResourceOwnershipFromContext(ctx)
   607  	must.BeTrue(ok)
   608  	return v
   609  }
   610  
   611  func WithUploadConfig(ctx context.Context, v *UploadConfig) context.Context {
   612  	return contextx.WithValue(ctx, CtxUploadConfig{}, v)
   613  }
   614  
   615  func WithUploadConfigContext(v *UploadConfig) contextx.WithContext {
   616  	return func(ctx context.Context) context.Context {
   617  		return contextx.WithValue(ctx, CtxUploadConfig{}, v)
   618  	}
   619  }
   620  
   621  func UploadConfigFromContext(ctx context.Context) (*UploadConfig, bool) {
   622  	v, ok := ctx.Value(CtxUploadConfig{}).(*UploadConfig)
   623  	return v, ok
   624  }
   625  
   626  func MustUploadConfigFromContext(ctx context.Context) *UploadConfig {
   627  	v, ok := UploadConfigFromContext(ctx)
   628  	must.BeTrue(ok)
   629  	return v
   630  }
   631  
   632  func WithWasmDBConfig(ctx context.Context, v *WasmDBConfig) context.Context {
   633  	return contextx.WithValue(ctx, CtxWasmDBConfig{}, v)
   634  }
   635  
   636  func WithWasmDBConfigContext(v *WasmDBConfig) contextx.WithContext {
   637  	return func(ctx context.Context) context.Context {
   638  		return contextx.WithValue(ctx, CtxWasmDBConfig{}, v)
   639  	}
   640  }
   641  
   642  func WasmDBConfigFromContext(ctx context.Context) (*WasmDBConfig, bool) {
   643  	v, ok := ctx.Value(CtxWasmDBConfig{}).(*WasmDBConfig)
   644  	return v, ok
   645  }
   646  
   647  func MustWasmDBConfigFromContext(ctx context.Context) *WasmDBConfig {
   648  	v, ok := WasmDBConfigFromContext(ctx)
   649  	must.BeTrue(ok)
   650  	return v
   651  }
   652  
   653  func WithEventID(ctx context.Context, v string) context.Context {
   654  	return contextx.WithValue(ctx, CtxEventID{}, v)
   655  }
   656  
   657  func WithEventIDContext(v string) contextx.WithContext {
   658  	return func(ctx context.Context) context.Context {
   659  		return contextx.WithValue(ctx, CtxEventID{}, v)
   660  	}
   661  }
   662  
   663  func EventIDFromContext(ctx context.Context) (string, bool) {
   664  	v, ok := ctx.Value(CtxEventID{}).(string)
   665  	return v, ok
   666  }
   667  
   668  func MustEventIDFromContext(ctx context.Context) string {
   669  	v, ok := EventIDFromContext(ctx)
   670  	must.BeTrue(ok)
   671  	return v
   672  }
   673  
   674  func WithTrafficLimit(ctx context.Context, r *models.TrafficLimit) context.Context {
   675  	_r := *r
   676  	return contextx.WithValue(ctx, CtxTrafficLimit{}, &_r)
   677  }
   678  
   679  func WithTrafficLimitContext(r *models.TrafficLimit) contextx.WithContext {
   680  	return func(ctx context.Context) context.Context {
   681  		return WithTrafficLimit(ctx, r)
   682  	}
   683  }
   684  
   685  func TrafficLimitFromContext(ctx context.Context) (*models.TrafficLimit, bool) {
   686  	v, ok := ctx.Value(CtxTrafficLimit{}).(*models.TrafficLimit)
   687  	return v, ok
   688  }
   689  
   690  func MustTrafficLimitFromContext(ctx context.Context) *models.TrafficLimit {
   691  	v, ok := TrafficLimitFromContext(ctx)
   692  	must.BeTrue(ok)
   693  	return v
   694  }
   695  
   696  func WithMetricsCenterConfig(ctx context.Context, v *MetricsCenterConfig) context.Context {
   697  	return contextx.WithValue(ctx, CtxMetricsCenterConfig{}, v)
   698  }
   699  
   700  func WithMetricsCenterConfigContext(v *MetricsCenterConfig) contextx.WithContext {
   701  	return func(ctx context.Context) context.Context {
   702  		return contextx.WithValue(ctx, CtxMetricsCenterConfig{}, v)
   703  	}
   704  }
   705  
   706  func MetricsCenterConfigFromContext(ctx context.Context) (*MetricsCenterConfig, bool) {
   707  	v, ok := ctx.Value(CtxMetricsCenterConfig{}).(*MetricsCenterConfig)
   708  	return v, ok
   709  }
   710  
   711  func MustMetricsCenterConfigFromContext(ctx context.Context) *MetricsCenterConfig {
   712  	v, ok := MetricsCenterConfigFromContext(ctx)
   713  	must.BeTrue(ok)
   714  	return v
   715  }
   716  
   717  func WithRobotNotifierConfig(ctx context.Context, v *RobotNotifierConfig) context.Context {
   718  	return contextx.WithValue(ctx, CtxRobotNotifierConfig{}, v)
   719  }
   720  
   721  func WithRobotNotifierConfigContext(v *RobotNotifierConfig) contextx.WithContext {
   722  	return func(ctx context.Context) context.Context {
   723  		return contextx.WithValue(ctx, CtxRobotNotifierConfig{}, v)
   724  	}
   725  }
   726  
   727  func RobotNotifierConfigFromContext(ctx context.Context) (*RobotNotifierConfig, bool) {
   728  	v, ok := ctx.Value(CtxRobotNotifierConfig{}).(*RobotNotifierConfig)
   729  	return v, ok
   730  }
   731  
   732  func MustRobotNotifierConfigFromContext(ctx context.Context) *RobotNotifierConfig {
   733  	v, ok := RobotNotifierConfigFromContext(ctx)
   734  	must.BeTrue(ok)
   735  	return v
   736  }
   737  
   738  func WithWasmApiServer(ctx context.Context, v wasmapi.Server) context.Context {
   739  	return contextx.WithValue(ctx, CtxWasmApiServer{}, v)
   740  }
   741  
   742  func WithWasmApiServerContext(v wasmapi.Server) contextx.WithContext {
   743  	return func(ctx context.Context) context.Context {
   744  		return contextx.WithValue(ctx, CtxWasmApiServer{}, v)
   745  	}
   746  }
   747  
   748  func WasmApiServerFromContext(ctx context.Context) (wasmapi.Server, bool) {
   749  	v, ok := ctx.Value(CtxWasmApiServer{}).(wasmapi.Server)
   750  	return v, ok
   751  }
   752  
   753  func MustWasmApiServerFromContext(ctx context.Context) wasmapi.Server {
   754  	v, ok := WasmApiServerFromContext(ctx)
   755  	must.BeTrue(ok)
   756  	return v
   757  }
   758  
   759  func WithOperators(ctx context.Context, v []models.Operator) context.Context {
   760  	return contextx.WithValue(ctx, CtxOperators{}, v)
   761  }
   762  
   763  func WithOperatorsContext(v []models.Operator) contextx.WithContext {
   764  	return func(ctx context.Context) context.Context {
   765  		return contextx.WithValue(ctx, CtxOperators{}, v)
   766  	}
   767  }
   768  
   769  func OperatorsFromContext(ctx context.Context) ([]models.Operator, bool) {
   770  	v, ok := ctx.Value(CtxOperators{}).([]models.Operator)
   771  	return v, ok
   772  }
   773  
   774  func MustOperatorsFromContext(ctx context.Context) []models.Operator {
   775  	v, ok := OperatorsFromContext(ctx)
   776  	must.BeTrue(ok)
   777  	return v
   778  }
   779  
   780  func WithProjectOperator(ctx context.Context, v *models.ProjectOperator) context.Context {
   781  	return contextx.WithValue(ctx, CtxProjectOperator{}, v)
   782  }
   783  
   784  func WithProjectOperatorContext(v *models.ProjectOperator) contextx.WithContext {
   785  	return func(ctx context.Context) context.Context {
   786  		return contextx.WithValue(ctx, CtxProjectOperator{}, v)
   787  	}
   788  }
   789  
   790  func ProjectOperatorFromContext(ctx context.Context) (*models.ProjectOperator, bool) {
   791  	v, ok := ctx.Value(CtxProjectOperator{}).(*models.ProjectOperator)
   792  	return v, ok
   793  }
   794  
   795  func MustProjectOperatorFromContext(ctx context.Context) *models.ProjectOperator {
   796  	v, ok := ProjectOperatorFromContext(ctx)
   797  	must.BeTrue(ok)
   798  	return v
   799  }
   800  
   801  func WithOperatorPool(ctx context.Context, v optypes.Pool) context.Context {
   802  	return contextx.WithValue(ctx, CtxOperatorPool{}, v)
   803  }
   804  
   805  func WithOperatorPoolContext(v optypes.Pool) contextx.WithContext {
   806  	return func(ctx context.Context) context.Context {
   807  		return contextx.WithValue(ctx, CtxOperatorPool{}, v)
   808  	}
   809  }
   810  
   811  func OperatorPoolFromContext(ctx context.Context) (optypes.Pool, bool) {
   812  	v, ok := ctx.Value(CtxOperatorPool{}).(optypes.Pool)
   813  	return v, ok
   814  }
   815  
   816  func MustOperatorPoolFromContext(ctx context.Context) optypes.Pool {
   817  	v, ok := OperatorPoolFromContext(ctx)
   818  	must.BeTrue(ok)
   819  	return v
   820  }
   821  
   822  func WithMaxWasmConsumeFuel(ctx context.Context, v uint64) context.Context {
   823  	return contextx.WithValue(ctx, CtxMaxWasmConsumeFuel{}, v)
   824  }
   825  
   826  func WithMaxWasmConsumeFuelContext(v uint64) contextx.WithContext {
   827  	return func(ctx context.Context) context.Context {
   828  		return contextx.WithValue(ctx, CtxMaxWasmConsumeFuel{}, v)
   829  	}
   830  }
   831  
   832  func MaxWasmConsumeFuelFromContext(ctx context.Context) (uint64, bool) {
   833  	v, ok := ctx.Value(CtxMaxWasmConsumeFuel{}).(uint64)
   834  	return v, ok
   835  }
   836  
   837  func MustMaxWasmConsumeFuelFromContext(ctx context.Context) uint64 {
   838  	v, ok := MaxWasmConsumeFuelFromContext(ctx)
   839  	must.BeTrue(ok)
   840  	return v
   841  }
   842  
   843  func WithEnableTrafficLimit(ctx context.Context, v bool) context.Context {
   844  	return contextx.WithValue(ctx, CtxEnableTrafficLimit{}, v)
   845  }
   846  
   847  func WithEnableTrafficLimitContext(v bool) contextx.WithContext {
   848  	return func(ctx context.Context) context.Context {
   849  		return WithEnableTrafficLimit(ctx, v)
   850  	}
   851  }
   852  
   853  func EnableTrafficLimitFromContext(ctx context.Context) bool {
   854  	v, ok := ctx.Value(CtxEnableTrafficLimit{}).(bool)
   855  	return v && ok
   856  }
   857  
   858  func WithProjectFilter(ctx context.Context, f *ProjectFilter) context.Context {
   859  	return contextx.WithValue(ctx, CtxProjectFilter{}, f)
   860  }
   861  
   862  func WithProjectFilterContext(f *ProjectFilter) contextx.WithContext {
   863  	return func(ctx context.Context) context.Context {
   864  		return WithProjectFilter(ctx, f)
   865  	}
   866  }
   867  
   868  func ProjectFilterFromContext(ctx context.Context) (*ProjectFilter, bool) {
   869  	v, ok := ctx.Value(CtxProjectFilter{}).(*ProjectFilter)
   870  	return v, ok && v != nil
   871  }
   872  
   873  func MustProjectFilterFromContext(ctx context.Context) *ProjectFilter {
   874  	v, ok := ProjectFilterFromContext(ctx)
   875  	must.BeTrue(ok)
   876  	return v
   877  }