37 lines
517 B
Go
37 lines
517 B
Go
package runtime
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
type Option func(o *Options)
|
|
|
|
type Options struct {
|
|
ID string
|
|
Type string
|
|
|
|
// 自定义参数
|
|
Context context.Context
|
|
}
|
|
|
|
func WithID(id string) Option {
|
|
return func(o *Options) {
|
|
o.ID = id
|
|
}
|
|
}
|
|
|
|
func WithType(t string) Option {
|
|
return func(o *Options) {
|
|
o.Type = t
|
|
}
|
|
}
|
|
|
|
func SetRuntimeOption(k, v interface{}) Option {
|
|
return func(o *Options) {
|
|
if o.Context == nil {
|
|
o.Context = context.Background()
|
|
}
|
|
o.Context = context.WithValue(o.Context, k, v)
|
|
}
|
|
}
|