How to use Get method of targets Package

Best Syzkaller code snippet using targets.Get

parse.go

Source:parse.go Github

copy

Full Screen

...34 formatNamespace = "namespace"35)36// ErrTargetsOffline - Indicates single/multiple target failures.37var ErrTargetsOffline = errors.New("one or more targets are offline. Please use `mc admin info --json` to check the offline targets")38// TestNotificationTargets is similar to GetNotificationTargets()39// avoids explicit registration.40func TestNotificationTargets(ctx context.Context, cfg config.Config, transport *http.Transport, targetIDs []event.TargetID) error {41 test := true42 returnOnTargetError := true43 targets, err := RegisterNotificationTargets(ctx, cfg, transport, targetIDs, test, returnOnTargetError)44 if err == nil {45 // Close all targets since we are only testing connections.46 for _, t := range targets.TargetMap() {47 _ = t.Close()48 }49 }50 return err51}52// GetNotificationTargets registers and initializes all notification53// targets, returns error if any.54func GetNotificationTargets(ctx context.Context, cfg config.Config, transport *http.Transport, test bool) (*event.TargetList, error) {55 returnOnTargetError := false56 return RegisterNotificationTargets(ctx, cfg, transport, nil, test, returnOnTargetError)57}58// RegisterNotificationTargets - returns TargetList which contains enabled targets in serverConfig.59// A new notification target is added like below60// * Add a new target in pkg/event/target package.61// * Add newly added target configuration to serverConfig.Notify.<TARGET_NAME>.62// * Handle the configuration in this function to create/add into TargetList.63func RegisterNotificationTargets(ctx context.Context, cfg config.Config, transport *http.Transport, targetIDs []event.TargetID, test bool, returnOnTargetError bool) (*event.TargetList, error) {64 targetList, err := FetchRegisteredTargets(ctx, cfg, transport, test, returnOnTargetError)65 if err != nil {66 return targetList, err67 }68 if test {69 // Verify if user is trying to disable already configured70 // notification targets, based on their target IDs71 for _, targetID := range targetIDs {72 if !targetList.Exists(targetID) {73 return nil, config.Errorf(74 "Unable to disable configured targets '%v'",75 targetID)76 }77 }78 }79 return targetList, nil80}81// FetchRegisteredTargets - Returns a set of configured TargetList82// If `returnOnTargetError` is set to true, The function returns when a target initialization fails83// Else, the function will return a complete TargetList irrespective of errors84func FetchRegisteredTargets(ctx context.Context, cfg config.Config, transport *http.Transport, test bool, returnOnTargetError bool) (_ *event.TargetList, err error) {85 targetList := event.NewTargetList()86 var targetsOffline bool87 defer func() {88 // Automatically close all connections to targets when an error occur.89 // Close all the targets if returnOnTargetError is set90 // Else, close only the failed targets91 if err != nil && returnOnTargetError {92 for _, t := range targetList.TargetMap() {93 _ = t.Close()94 }95 }96 }()97 if err = checkValidNotificationKeys(cfg); err != nil {98 return nil, err99 }100 amqpTargets, err := GetNotifyAMQP(cfg[config.NotifyAMQPSubSys])101 if err != nil {102 return nil, err103 }104 esTargets, err := GetNotifyES(cfg[config.NotifyESSubSys], transport)105 if err != nil {106 return nil, err107 }108 kafkaTargets, err := GetNotifyKafka(cfg[config.NotifyKafkaSubSys])109 if err != nil {110 return nil, err111 }112 mqttTargets, err := GetNotifyMQTT(cfg[config.NotifyMQTTSubSys], transport.TLSClientConfig.RootCAs)113 if err != nil {114 return nil, err115 }116 mysqlTargets, err := GetNotifyMySQL(cfg[config.NotifyMySQLSubSys])117 if err != nil {118 return nil, err119 }120 natsTargets, err := GetNotifyNATS(cfg[config.NotifyNATSSubSys], transport.TLSClientConfig.RootCAs)121 if err != nil {122 return nil, err123 }124 nsqTargets, err := GetNotifyNSQ(cfg[config.NotifyNSQSubSys])125 if err != nil {126 return nil, err127 }128 postgresTargets, err := GetNotifyPostgres(cfg[config.NotifyPostgresSubSys])129 if err != nil {130 return nil, err131 }132 redisTargets, err := GetNotifyRedis(cfg[config.NotifyRedisSubSys])133 if err != nil {134 return nil, err135 }136 webhookTargets, err := GetNotifyWebhook(cfg[config.NotifyWebhookSubSys], transport)137 if err != nil {138 return nil, err139 }140 for id, args := range amqpTargets {141 if !args.Enable {142 continue143 }144 newTarget, err := target.NewAMQPTarget(id, args, ctx.Done(), logger.LogOnceIf, test)145 if err != nil {146 targetsOffline = true147 if returnOnTargetError {148 return nil, err149 }150 _ = newTarget.Close()151 }152 if err = targetList.Add(newTarget); err != nil {153 logger.LogIf(context.Background(), err)154 if returnOnTargetError {155 return nil, err156 }157 }158 }159 for id, args := range esTargets {160 if !args.Enable {161 continue162 }163 newTarget, err := target.NewElasticsearchTarget(id, args, ctx.Done(), logger.LogOnceIf, test)164 if err != nil {165 targetsOffline = true166 if returnOnTargetError {167 return nil, err168 }169 _ = newTarget.Close()170 }171 if err = targetList.Add(newTarget); err != nil {172 logger.LogIf(context.Background(), err)173 if returnOnTargetError {174 return nil, err175 }176 }177 }178 for id, args := range kafkaTargets {179 if !args.Enable {180 continue181 }182 args.TLS.RootCAs = transport.TLSClientConfig.RootCAs183 newTarget, err := target.NewKafkaTarget(id, args, ctx.Done(), logger.LogOnceIf, test)184 if err != nil {185 targetsOffline = true186 if returnOnTargetError {187 return nil, err188 }189 _ = newTarget.Close()190 }191 if err = targetList.Add(newTarget); err != nil {192 logger.LogIf(context.Background(), err)193 if returnOnTargetError {194 return nil, err195 }196 }197 }198 for id, args := range mqttTargets {199 if !args.Enable {200 continue201 }202 args.RootCAs = transport.TLSClientConfig.RootCAs203 newTarget, err := target.NewMQTTTarget(id, args, ctx.Done(), logger.LogOnceIf, test)204 if err != nil {205 targetsOffline = true206 if returnOnTargetError {207 return nil, err208 }209 _ = newTarget.Close()210 }211 if err = targetList.Add(newTarget); err != nil {212 logger.LogIf(context.Background(), err)213 if returnOnTargetError {214 return nil, err215 }216 }217 }218 for id, args := range mysqlTargets {219 if !args.Enable {220 continue221 }222 newTarget, err := target.NewMySQLTarget(id, args, ctx.Done(), logger.LogOnceIf, test)223 if err != nil {224 targetsOffline = true225 if returnOnTargetError {226 return nil, err227 }228 _ = newTarget.Close()229 }230 if err = targetList.Add(newTarget); err != nil {231 logger.LogIf(context.Background(), err)232 if returnOnTargetError {233 return nil, err234 }235 }236 }237 for id, args := range natsTargets {238 if !args.Enable {239 continue240 }241 newTarget, err := target.NewNATSTarget(id, args, ctx.Done(), logger.LogOnceIf, test)242 if err != nil {243 targetsOffline = true244 if returnOnTargetError {245 return nil, err246 }247 _ = newTarget.Close()248 }249 if err = targetList.Add(newTarget); err != nil {250 logger.LogIf(context.Background(), err)251 if returnOnTargetError {252 return nil, err253 }254 }255 }256 for id, args := range nsqTargets {257 if !args.Enable {258 continue259 }260 newTarget, err := target.NewNSQTarget(id, args, ctx.Done(), logger.LogOnceIf, test)261 if err != nil {262 targetsOffline = true263 if returnOnTargetError {264 return nil, err265 }266 _ = newTarget.Close()267 }268 if err = targetList.Add(newTarget); err != nil {269 logger.LogIf(context.Background(), err)270 if returnOnTargetError {271 return nil, err272 }273 }274 }275 for id, args := range postgresTargets {276 if !args.Enable {277 continue278 }279 newTarget, err := target.NewPostgreSQLTarget(id, args, ctx.Done(), logger.LogOnceIf, test)280 if err != nil {281 targetsOffline = true282 if returnOnTargetError {283 return nil, err284 }285 _ = newTarget.Close()286 }287 if err = targetList.Add(newTarget); err != nil {288 logger.LogIf(context.Background(), err)289 if returnOnTargetError {290 return nil, err291 }292 }293 }294 for id, args := range redisTargets {295 if !args.Enable {296 continue297 }298 newTarget, err := target.NewRedisTarget(id, args, ctx.Done(), logger.LogOnceIf, test)299 if err != nil {300 targetsOffline = true301 if returnOnTargetError {302 return nil, err303 }304 _ = newTarget.Close()305 }306 if err = targetList.Add(newTarget); err != nil {307 logger.LogIf(context.Background(), err)308 if returnOnTargetError {309 return nil, err310 }311 }312 }313 for id, args := range webhookTargets {314 if !args.Enable {315 continue316 }317 newTarget, err := target.NewWebhookTarget(ctx, id, args, logger.LogOnceIf, transport, test)318 if err != nil {319 targetsOffline = true320 if returnOnTargetError {321 return nil, err322 }323 _ = newTarget.Close()324 }325 if err = targetList.Add(newTarget); err != nil {326 logger.LogIf(context.Background(), err)327 if returnOnTargetError {328 return nil, err329 }330 }331 }332 if targetsOffline {333 return targetList, ErrTargetsOffline334 }335 return targetList, nil336}337// DefaultNotificationKVS - default notification list of kvs.338var (339 DefaultNotificationKVS = map[string]config.KVS{340 config.NotifyAMQPSubSys: DefaultAMQPKVS,341 config.NotifyKafkaSubSys: DefaultKafkaKVS,342 config.NotifyMQTTSubSys: DefaultMQTTKVS,343 config.NotifyMySQLSubSys: DefaultMySQLKVS,344 config.NotifyNATSSubSys: DefaultNATSKVS,345 config.NotifyNSQSubSys: DefaultNSQKVS,346 config.NotifyPostgresSubSys: DefaultPostgresKVS,347 config.NotifyRedisSubSys: DefaultRedisKVS,348 config.NotifyWebhookSubSys: DefaultWebhookKVS,349 config.NotifyESSubSys: DefaultESKVS,350 }351)352func checkValidNotificationKeys(cfg config.Config) error {353 for subSys, tgt := range cfg {354 validKVS, ok := DefaultNotificationKVS[subSys]355 if !ok {356 continue357 }358 for tname, kv := range tgt {359 subSysTarget := subSys360 if tname != config.Default {361 subSysTarget = subSys + config.SubSystemSeparator + tname362 }363 if v, ok := kv.Lookup(config.Enable); ok && v == config.EnableOn {364 if err := config.CheckValidKeys(subSysTarget, kv, validKVS); err != nil {365 return err366 }367 }368 }369 }370 return nil371}372func mergeTargets(cfgTargets map[string]config.KVS, envname string, defaultKVS config.KVS) map[string]config.KVS {373 newCfgTargets := make(map[string]config.KVS)374 for _, e := range env.List(envname) {375 tgt := strings.TrimPrefix(e, envname+config.Default)376 if tgt == envname {377 tgt = config.Default378 }379 newCfgTargets[tgt] = defaultKVS380 }381 for tgt, kv := range cfgTargets {382 newCfgTargets[tgt] = kv383 }384 return newCfgTargets385}386// DefaultKakfaKVS - default KV for kafka target387var (388 DefaultKafkaKVS = config.KVS{389 config.KV{390 Key: config.Enable,391 Value: config.EnableOff,392 },393 config.KV{394 Key: target.KafkaTopic,395 Value: "",396 },397 config.KV{398 Key: target.KafkaBrokers,399 Value: "",400 },401 config.KV{402 Key: target.KafkaSASLUsername,403 Value: "",404 },405 config.KV{406 Key: target.KafkaSASLPassword,407 Value: "",408 },409 config.KV{410 Key: target.KafkaSASLMechanism,411 Value: "plain",412 },413 config.KV{414 Key: target.KafkaClientTLSCert,415 Value: "",416 },417 config.KV{418 Key: target.KafkaClientTLSKey,419 Value: "",420 },421 config.KV{422 Key: target.KafkaTLSClientAuth,423 Value: "0",424 },425 config.KV{426 Key: target.KafkaSASL,427 Value: config.EnableOff,428 },429 config.KV{430 Key: target.KafkaTLS,431 Value: config.EnableOff,432 },433 config.KV{434 Key: target.KafkaTLSSkipVerify,435 Value: config.EnableOff,436 },437 config.KV{438 Key: target.KafkaQueueLimit,439 Value: "0",440 },441 config.KV{442 Key: target.KafkaQueueDir,443 Value: "",444 },445 config.KV{446 Key: target.KafkaVersion,447 Value: "",448 },449 }450)451// GetNotifyKafka - returns a map of registered notification 'kafka' targets452func GetNotifyKafka(kafkaKVS map[string]config.KVS) (map[string]target.KafkaArgs, error) {453 kafkaTargets := make(map[string]target.KafkaArgs)454 for k, kv := range mergeTargets(kafkaKVS, target.EnvKafkaEnable, DefaultKafkaKVS) {455 enableEnv := target.EnvKafkaEnable456 if k != config.Default {457 enableEnv = enableEnv + config.Default + k458 }459 enabled, err := config.ParseBool(env.Get(enableEnv, kv.Get(config.Enable)))460 if err != nil {461 return nil, err462 }463 if !enabled {464 continue465 }466 var brokers []xnet.Host467 brokersEnv := target.EnvKafkaBrokers468 if k != config.Default {469 brokersEnv = brokersEnv + config.Default + k470 }471 kafkaBrokers := env.Get(brokersEnv, kv.Get(target.KafkaBrokers))472 if len(kafkaBrokers) == 0 {473 return nil, config.Errorf("kafka 'brokers' cannot be empty")474 }475 for _, s := range strings.Split(kafkaBrokers, config.ValueSeparator) {476 var host *xnet.Host477 host, err = xnet.ParseHost(s)478 if err != nil {479 break480 }481 brokers = append(brokers, *host)482 }483 if err != nil {484 return nil, err485 }486 queueLimitEnv := target.EnvKafkaQueueLimit487 if k != config.Default {488 queueLimitEnv = queueLimitEnv + config.Default + k489 }490 queueLimit, err := strconv.ParseUint(env.Get(queueLimitEnv, kv.Get(target.KafkaQueueLimit)), 10, 64)491 if err != nil {492 return nil, err493 }494 clientAuthEnv := target.EnvKafkaTLSClientAuth495 if k != config.Default {496 clientAuthEnv = clientAuthEnv + config.Default + k497 }498 clientAuth, err := strconv.Atoi(env.Get(clientAuthEnv, kv.Get(target.KafkaTLSClientAuth)))499 if err != nil {500 return nil, err501 }502 topicEnv := target.EnvKafkaTopic503 if k != config.Default {504 topicEnv = topicEnv + config.Default + k505 }506 queueDirEnv := target.EnvKafkaQueueDir507 if k != config.Default {508 queueDirEnv = queueDirEnv + config.Default + k509 }510 versionEnv := target.EnvKafkaVersion511 if k != config.Default {512 versionEnv = versionEnv + config.Default + k513 }514 kafkaArgs := target.KafkaArgs{515 Enable: enabled,516 Brokers: brokers,517 Topic: env.Get(topicEnv, kv.Get(target.KafkaTopic)),518 QueueDir: env.Get(queueDirEnv, kv.Get(target.KafkaQueueDir)),519 QueueLimit: queueLimit,520 Version: env.Get(versionEnv, kv.Get(target.KafkaVersion)),521 }522 tlsEnableEnv := target.EnvKafkaTLS523 if k != config.Default {524 tlsEnableEnv = tlsEnableEnv + config.Default + k525 }526 tlsSkipVerifyEnv := target.EnvKafkaTLSSkipVerify527 if k != config.Default {528 tlsSkipVerifyEnv = tlsSkipVerifyEnv + config.Default + k529 }530 tlsClientTLSCertEnv := target.EnvKafkaClientTLSCert531 if k != config.Default {532 tlsClientTLSCertEnv = tlsClientTLSCertEnv + config.Default + k533 }534 tlsClientTLSKeyEnv := target.EnvKafkaClientTLSKey535 if k != config.Default {536 tlsClientTLSKeyEnv = tlsClientTLSKeyEnv + config.Default + k537 }538 kafkaArgs.TLS.Enable = env.Get(tlsEnableEnv, kv.Get(target.KafkaTLS)) == config.EnableOn539 kafkaArgs.TLS.SkipVerify = env.Get(tlsSkipVerifyEnv, kv.Get(target.KafkaTLSSkipVerify)) == config.EnableOn540 kafkaArgs.TLS.ClientAuth = tls.ClientAuthType(clientAuth)541 kafkaArgs.TLS.ClientTLSCert = env.Get(tlsClientTLSCertEnv, kv.Get(target.KafkaClientTLSCert))542 kafkaArgs.TLS.ClientTLSKey = env.Get(tlsClientTLSKeyEnv, kv.Get(target.KafkaClientTLSKey))543 saslEnableEnv := target.EnvKafkaSASLEnable544 if k != config.Default {545 saslEnableEnv = saslEnableEnv + config.Default + k546 }547 saslUsernameEnv := target.EnvKafkaSASLUsername548 if k != config.Default {549 saslUsernameEnv = saslUsernameEnv + config.Default + k550 }551 saslPasswordEnv := target.EnvKafkaSASLPassword552 if k != config.Default {553 saslPasswordEnv = saslPasswordEnv + config.Default + k554 }555 saslMechanismEnv := target.EnvKafkaSASLMechanism556 if k != config.Default {557 saslMechanismEnv = saslMechanismEnv + config.Default + k558 }559 kafkaArgs.SASL.Enable = env.Get(saslEnableEnv, kv.Get(target.KafkaSASL)) == config.EnableOn560 kafkaArgs.SASL.User = env.Get(saslUsernameEnv, kv.Get(target.KafkaSASLUsername))561 kafkaArgs.SASL.Password = env.Get(saslPasswordEnv, kv.Get(target.KafkaSASLPassword))562 kafkaArgs.SASL.Mechanism = env.Get(saslMechanismEnv, kv.Get(target.KafkaSASLMechanism))563 if err = kafkaArgs.Validate(); err != nil {564 return nil, err565 }566 kafkaTargets[k] = kafkaArgs567 }568 return kafkaTargets, nil569}570// DefaultMQTTKVS - default MQTT config571var (572 DefaultMQTTKVS = config.KVS{573 config.KV{574 Key: config.Enable,575 Value: config.EnableOff,576 },577 config.KV{578 Key: target.MqttBroker,579 Value: "",580 },581 config.KV{582 Key: target.MqttTopic,583 Value: "",584 },585 config.KV{586 Key: target.MqttPassword,587 Value: "",588 },589 config.KV{590 Key: target.MqttUsername,591 Value: "",592 },593 config.KV{594 Key: target.MqttQoS,595 Value: "0",596 },597 config.KV{598 Key: target.MqttKeepAliveInterval,599 Value: "0s",600 },601 config.KV{602 Key: target.MqttReconnectInterval,603 Value: "0s",604 },605 config.KV{606 Key: target.MqttQueueDir,607 Value: "",608 },609 config.KV{610 Key: target.MqttQueueLimit,611 Value: "0",612 },613 }614)615// GetNotifyMQTT - returns a map of registered notification 'mqtt' targets616func GetNotifyMQTT(mqttKVS map[string]config.KVS, rootCAs *x509.CertPool) (map[string]target.MQTTArgs, error) {617 mqttTargets := make(map[string]target.MQTTArgs)618 for k, kv := range mergeTargets(mqttKVS, target.EnvMQTTEnable, DefaultMQTTKVS) {619 enableEnv := target.EnvMQTTEnable620 if k != config.Default {621 enableEnv = enableEnv + config.Default + k622 }623 enabled, err := config.ParseBool(env.Get(enableEnv, kv.Get(config.Enable)))624 if err != nil {625 return nil, err626 }627 if !enabled {628 continue629 }630 brokerEnv := target.EnvMQTTBroker631 if k != config.Default {632 brokerEnv = brokerEnv + config.Default + k633 }634 brokerURL, err := xnet.ParseURL(env.Get(brokerEnv, kv.Get(target.MqttBroker)))635 if err != nil {636 return nil, err637 }638 reconnectIntervalEnv := target.EnvMQTTReconnectInterval639 if k != config.Default {640 reconnectIntervalEnv = reconnectIntervalEnv + config.Default + k641 }642 reconnectInterval, err := time.ParseDuration(env.Get(reconnectIntervalEnv,643 kv.Get(target.MqttReconnectInterval)))644 if err != nil {645 return nil, err646 }647 keepAliveIntervalEnv := target.EnvMQTTKeepAliveInterval648 if k != config.Default {649 keepAliveIntervalEnv = keepAliveIntervalEnv + config.Default + k650 }651 keepAliveInterval, err := time.ParseDuration(env.Get(keepAliveIntervalEnv,652 kv.Get(target.MqttKeepAliveInterval)))653 if err != nil {654 return nil, err655 }656 queueLimitEnv := target.EnvMQTTQueueLimit657 if k != config.Default {658 queueLimitEnv = queueLimitEnv + config.Default + k659 }660 queueLimit, err := strconv.ParseUint(env.Get(queueLimitEnv, kv.Get(target.MqttQueueLimit)), 10, 64)661 if err != nil {662 return nil, err663 }664 qosEnv := target.EnvMQTTQoS665 if k != config.Default {666 qosEnv = qosEnv + config.Default + k667 }668 // Parse uint8 value669 qos, err := strconv.ParseUint(env.Get(qosEnv, kv.Get(target.MqttQoS)), 10, 8)670 if err != nil {671 return nil, err672 }673 topicEnv := target.EnvMQTTTopic674 if k != config.Default {675 topicEnv = topicEnv + config.Default + k676 }677 usernameEnv := target.EnvMQTTUsername678 if k != config.Default {679 usernameEnv = usernameEnv + config.Default + k680 }681 passwordEnv := target.EnvMQTTPassword682 if k != config.Default {683 passwordEnv = passwordEnv + config.Default + k684 }685 queueDirEnv := target.EnvMQTTQueueDir686 if k != config.Default {687 queueDirEnv = queueDirEnv + config.Default + k688 }689 mqttArgs := target.MQTTArgs{690 Enable: enabled,691 Broker: *brokerURL,692 Topic: env.Get(topicEnv, kv.Get(target.MqttTopic)),693 QoS: byte(qos),694 User: env.Get(usernameEnv, kv.Get(target.MqttUsername)),695 Password: env.Get(passwordEnv, kv.Get(target.MqttPassword)),696 MaxReconnectInterval: reconnectInterval,697 KeepAlive: keepAliveInterval,698 RootCAs: rootCAs,699 QueueDir: env.Get(queueDirEnv, kv.Get(target.MqttQueueDir)),700 QueueLimit: queueLimit,701 }702 if err = mqttArgs.Validate(); err != nil {703 return nil, err704 }705 mqttTargets[k] = mqttArgs706 }707 return mqttTargets, nil708}709// DefaultMySQLKVS - default KV for MySQL710var (711 DefaultMySQLKVS = config.KVS{712 config.KV{713 Key: config.Enable,714 Value: config.EnableOff,715 },716 config.KV{717 Key: target.MySQLFormat,718 Value: formatNamespace,719 },720 config.KV{721 Key: target.MySQLDSNString,722 Value: "",723 },724 config.KV{725 Key: target.MySQLTable,726 Value: "",727 },728 config.KV{729 Key: target.MySQLQueueDir,730 Value: "",731 },732 config.KV{733 Key: target.MySQLQueueLimit,734 Value: "0",735 },736 config.KV{737 Key: target.MySQLMaxOpenConnections,738 Value: "2",739 },740 }741)742// GetNotifyMySQL - returns a map of registered notification 'mysql' targets743func GetNotifyMySQL(mysqlKVS map[string]config.KVS) (map[string]target.MySQLArgs, error) {744 mysqlTargets := make(map[string]target.MySQLArgs)745 for k, kv := range mergeTargets(mysqlKVS, target.EnvMySQLEnable, DefaultMySQLKVS) {746 enableEnv := target.EnvMySQLEnable747 if k != config.Default {748 enableEnv = enableEnv + config.Default + k749 }750 enabled, err := config.ParseBool(env.Get(enableEnv, kv.Get(config.Enable)))751 if err != nil {752 return nil, err753 }754 if !enabled {755 continue756 }757 queueLimitEnv := target.EnvMySQLQueueLimit758 if k != config.Default {759 queueLimitEnv = queueLimitEnv + config.Default + k760 }761 queueLimit, err := strconv.ParseUint(env.Get(queueLimitEnv, kv.Get(target.MySQLQueueLimit)), 10, 64)762 if err != nil {763 return nil, err764 }765 formatEnv := target.EnvMySQLFormat766 if k != config.Default {767 formatEnv = formatEnv + config.Default + k768 }769 dsnStringEnv := target.EnvMySQLDSNString770 if k != config.Default {771 dsnStringEnv = dsnStringEnv + config.Default + k772 }773 tableEnv := target.EnvMySQLTable774 if k != config.Default {775 tableEnv = tableEnv + config.Default + k776 }777 queueDirEnv := target.EnvMySQLQueueDir778 if k != config.Default {779 queueDirEnv = queueDirEnv + config.Default + k780 }781 maxOpenConnectionsEnv := target.EnvMySQLMaxOpenConnections782 if k != config.Default {783 maxOpenConnectionsEnv = maxOpenConnectionsEnv + config.Default + k784 }785 maxOpenConnections, cErr := strconv.Atoi(env.Get(maxOpenConnectionsEnv, kv.Get(target.MySQLMaxOpenConnections)))786 if cErr != nil {787 return nil, cErr788 }789 mysqlArgs := target.MySQLArgs{790 Enable: enabled,791 Format: env.Get(formatEnv, kv.Get(target.MySQLFormat)),792 DSN: env.Get(dsnStringEnv, kv.Get(target.MySQLDSNString)),793 Table: env.Get(tableEnv, kv.Get(target.MySQLTable)),794 QueueDir: env.Get(queueDirEnv, kv.Get(target.MySQLQueueDir)),795 QueueLimit: queueLimit,796 MaxOpenConnections: maxOpenConnections,797 }798 if err = mysqlArgs.Validate(); err != nil {799 return nil, err800 }801 mysqlTargets[k] = mysqlArgs802 }803 return mysqlTargets, nil804}805// DefaultNATSKVS - NATS KV for nats config.806var (807 DefaultNATSKVS = config.KVS{808 config.KV{809 Key: config.Enable,810 Value: config.EnableOff,811 },812 config.KV{813 Key: target.NATSAddress,814 Value: "",815 },816 config.KV{817 Key: target.NATSSubject,818 Value: "",819 },820 config.KV{821 Key: target.NATSUsername,822 Value: "",823 },824 config.KV{825 Key: target.NATSPassword,826 Value: "",827 },828 config.KV{829 Key: target.NATSToken,830 Value: "",831 },832 config.KV{833 Key: target.NATSTLS,834 Value: config.EnableOff,835 },836 config.KV{837 Key: target.NATSTLSSkipVerify,838 Value: config.EnableOff,839 },840 config.KV{841 Key: target.NATSCertAuthority,842 Value: "",843 },844 config.KV{845 Key: target.NATSClientCert,846 Value: "",847 },848 config.KV{849 Key: target.NATSClientKey,850 Value: "",851 },852 config.KV{853 Key: target.NATSPingInterval,854 Value: "0",855 },856 config.KV{857 Key: target.NATSStreaming,858 Value: config.EnableOff,859 },860 config.KV{861 Key: target.NATSStreamingAsync,862 Value: config.EnableOff,863 },864 config.KV{865 Key: target.NATSStreamingMaxPubAcksInFlight,866 Value: "0",867 },868 config.KV{869 Key: target.NATSStreamingClusterID,870 Value: "",871 },872 config.KV{873 Key: target.NATSQueueDir,874 Value: "",875 },876 config.KV{877 Key: target.NATSQueueLimit,878 Value: "0",879 },880 }881)882// GetNotifyNATS - returns a map of registered notification 'nats' targets883func GetNotifyNATS(natsKVS map[string]config.KVS, rootCAs *x509.CertPool) (map[string]target.NATSArgs, error) {884 natsTargets := make(map[string]target.NATSArgs)885 for k, kv := range mergeTargets(natsKVS, target.EnvNATSEnable, DefaultNATSKVS) {886 enableEnv := target.EnvNATSEnable887 if k != config.Default {888 enableEnv = enableEnv + config.Default + k889 }890 enabled, err := config.ParseBool(env.Get(enableEnv, kv.Get(config.Enable)))891 if err != nil {892 return nil, err893 }894 if !enabled {895 continue896 }897 addressEnv := target.EnvNATSAddress898 if k != config.Default {899 addressEnv = addressEnv + config.Default + k900 }901 address, err := xnet.ParseHost(env.Get(addressEnv, kv.Get(target.NATSAddress)))902 if err != nil {903 return nil, err904 }905 pingIntervalEnv := target.EnvNATSPingInterval906 if k != config.Default {907 pingIntervalEnv = pingIntervalEnv + config.Default + k908 }909 pingInterval, err := strconv.ParseInt(env.Get(pingIntervalEnv, kv.Get(target.NATSPingInterval)), 10, 64)910 if err != nil {911 return nil, err912 }913 queueLimitEnv := target.EnvNATSQueueLimit914 if k != config.Default {915 queueLimitEnv = queueLimitEnv + config.Default + k916 }917 queueLimit, err := strconv.ParseUint(env.Get(queueLimitEnv, kv.Get(target.NATSQueueLimit)), 10, 64)918 if err != nil {919 return nil, err920 }921 tlsEnv := target.EnvNATSTLS922 if k != config.Default {923 tlsEnv = tlsEnv + config.Default + k924 }925 tlsSkipVerifyEnv := target.EnvNATSTLSSkipVerify926 if k != config.Default {927 tlsSkipVerifyEnv = tlsSkipVerifyEnv + config.Default + k928 }929 subjectEnv := target.EnvNATSSubject930 if k != config.Default {931 subjectEnv = subjectEnv + config.Default + k932 }933 usernameEnv := target.EnvNATSUsername934 if k != config.Default {935 usernameEnv = usernameEnv + config.Default + k936 }937 passwordEnv := target.EnvNATSPassword938 if k != config.Default {939 passwordEnv = passwordEnv + config.Default + k940 }941 tokenEnv := target.EnvNATSToken942 if k != config.Default {943 tokenEnv = tokenEnv + config.Default + k944 }945 queueDirEnv := target.EnvNATSQueueDir946 if k != config.Default {947 queueDirEnv = queueDirEnv + config.Default + k948 }949 certAuthorityEnv := target.EnvNATSCertAuthority950 if k != config.Default {951 certAuthorityEnv = certAuthorityEnv + config.Default + k952 }953 clientCertEnv := target.EnvNATSClientCert954 if k != config.Default {955 clientCertEnv = clientCertEnv + config.Default + k956 }957 clientKeyEnv := target.EnvNATSClientKey958 if k != config.Default {959 clientKeyEnv = clientKeyEnv + config.Default + k960 }961 natsArgs := target.NATSArgs{962 Enable: true,963 Address: *address,964 Subject: env.Get(subjectEnv, kv.Get(target.NATSSubject)),965 Username: env.Get(usernameEnv, kv.Get(target.NATSUsername)),966 Password: env.Get(passwordEnv, kv.Get(target.NATSPassword)),967 CertAuthority: env.Get(certAuthorityEnv, kv.Get(target.NATSCertAuthority)),968 ClientCert: env.Get(clientCertEnv, kv.Get(target.NATSClientCert)),969 ClientKey: env.Get(clientKeyEnv, kv.Get(target.NATSClientKey)),970 Token: env.Get(tokenEnv, kv.Get(target.NATSToken)),971 TLS: env.Get(tlsEnv, kv.Get(target.NATSTLS)) == config.EnableOn,972 TLSSkipVerify: env.Get(tlsSkipVerifyEnv, kv.Get(target.NATSTLSSkipVerify)) == config.EnableOn,973 PingInterval: pingInterval,974 QueueDir: env.Get(queueDirEnv, kv.Get(target.NATSQueueDir)),975 QueueLimit: queueLimit,976 RootCAs: rootCAs,977 }978 streamingEnableEnv := target.EnvNATSStreaming979 if k != config.Default {980 streamingEnableEnv = streamingEnableEnv + config.Default + k981 }982 streamingEnabled := env.Get(streamingEnableEnv, kv.Get(target.NATSStreaming)) == config.EnableOn983 if streamingEnabled {984 asyncEnv := target.EnvNATSStreamingAsync985 if k != config.Default {986 asyncEnv = asyncEnv + config.Default + k987 }988 maxPubAcksInflightEnv := target.EnvNATSStreamingMaxPubAcksInFlight989 if k != config.Default {990 maxPubAcksInflightEnv = maxPubAcksInflightEnv + config.Default + k991 }992 maxPubAcksInflight, err := strconv.Atoi(env.Get(maxPubAcksInflightEnv,993 kv.Get(target.NATSStreamingMaxPubAcksInFlight)))994 if err != nil {995 return nil, err996 }997 clusterIDEnv := target.EnvNATSStreamingClusterID998 if k != config.Default {999 clusterIDEnv = clusterIDEnv + config.Default + k1000 }1001 natsArgs.Streaming.Enable = streamingEnabled1002 natsArgs.Streaming.ClusterID = env.Get(clusterIDEnv, kv.Get(target.NATSStreamingClusterID))1003 natsArgs.Streaming.Async = env.Get(asyncEnv, kv.Get(target.NATSStreamingAsync)) == config.EnableOn1004 natsArgs.Streaming.MaxPubAcksInflight = maxPubAcksInflight1005 }1006 if err = natsArgs.Validate(); err != nil {1007 return nil, err1008 }1009 natsTargets[k] = natsArgs1010 }1011 return natsTargets, nil1012}1013// DefaultNSQKVS - NSQ KV for config1014var (1015 DefaultNSQKVS = config.KVS{1016 config.KV{1017 Key: config.Enable,1018 Value: config.EnableOff,1019 },1020 config.KV{1021 Key: target.NSQAddress,1022 Value: "",1023 },1024 config.KV{1025 Key: target.NSQTopic,1026 Value: "",1027 },1028 config.KV{1029 Key: target.NSQTLS,1030 Value: config.EnableOff,1031 },1032 config.KV{1033 Key: target.NSQTLSSkipVerify,1034 Value: config.EnableOff,1035 },1036 config.KV{1037 Key: target.NSQQueueDir,1038 Value: "",1039 },1040 config.KV{1041 Key: target.NSQQueueLimit,1042 Value: "0",1043 },1044 }1045)1046// GetNotifyNSQ - returns a map of registered notification 'nsq' targets1047func GetNotifyNSQ(nsqKVS map[string]config.KVS) (map[string]target.NSQArgs, error) {1048 nsqTargets := make(map[string]target.NSQArgs)1049 for k, kv := range mergeTargets(nsqKVS, target.EnvNSQEnable, DefaultNSQKVS) {1050 enableEnv := target.EnvNSQEnable1051 if k != config.Default {1052 enableEnv = enableEnv + config.Default + k1053 }1054 enabled, err := config.ParseBool(env.Get(enableEnv, kv.Get(config.Enable)))1055 if err != nil {1056 return nil, err1057 }1058 if !enabled {1059 continue1060 }1061 addressEnv := target.EnvNSQAddress1062 if k != config.Default {1063 addressEnv = addressEnv + config.Default + k1064 }1065 nsqdAddress, err := xnet.ParseHost(env.Get(addressEnv, kv.Get(target.NSQAddress)))1066 if err != nil {1067 return nil, err1068 }1069 tlsEnableEnv := target.EnvNSQTLS1070 if k != config.Default {1071 tlsEnableEnv = tlsEnableEnv + config.Default + k1072 }1073 tlsSkipVerifyEnv := target.EnvNSQTLSSkipVerify1074 if k != config.Default {1075 tlsSkipVerifyEnv = tlsSkipVerifyEnv + config.Default + k1076 }1077 queueLimitEnv := target.EnvNSQQueueLimit1078 if k != config.Default {1079 queueLimitEnv = queueLimitEnv + config.Default + k1080 }1081 queueLimit, err := strconv.ParseUint(env.Get(queueLimitEnv, kv.Get(target.NSQQueueLimit)), 10, 64)1082 if err != nil {1083 return nil, err1084 }1085 topicEnv := target.EnvNSQTopic1086 if k != config.Default {1087 topicEnv = topicEnv + config.Default + k1088 }1089 queueDirEnv := target.EnvNSQQueueDir1090 if k != config.Default {1091 queueDirEnv = queueDirEnv + config.Default + k1092 }1093 nsqArgs := target.NSQArgs{1094 Enable: enabled,1095 NSQDAddress: *nsqdAddress,1096 Topic: env.Get(topicEnv, kv.Get(target.NSQTopic)),1097 QueueDir: env.Get(queueDirEnv, kv.Get(target.NSQQueueDir)),1098 QueueLimit: queueLimit,1099 }1100 nsqArgs.TLS.Enable = env.Get(tlsEnableEnv, kv.Get(target.NSQTLS)) == config.EnableOn1101 nsqArgs.TLS.SkipVerify = env.Get(tlsSkipVerifyEnv, kv.Get(target.NSQTLSSkipVerify)) == config.EnableOn1102 if err = nsqArgs.Validate(); err != nil {1103 return nil, err1104 }1105 nsqTargets[k] = nsqArgs1106 }1107 return nsqTargets, nil1108}1109// DefaultPostgresKVS - default Postgres KV for server config.1110var (1111 DefaultPostgresKVS = config.KVS{1112 config.KV{1113 Key: config.Enable,1114 Value: config.EnableOff,1115 },1116 config.KV{1117 Key: target.PostgresFormat,1118 Value: formatNamespace,1119 },1120 config.KV{1121 Key: target.PostgresConnectionString,1122 Value: "",1123 },1124 config.KV{1125 Key: target.PostgresTable,1126 Value: "",1127 },1128 config.KV{1129 Key: target.PostgresQueueDir,1130 Value: "",1131 },1132 config.KV{1133 Key: target.PostgresQueueLimit,1134 Value: "0",1135 },1136 config.KV{1137 Key: target.PostgresMaxOpenConnections,1138 Value: "2",1139 },1140 }1141)1142// GetNotifyPostgres - returns a map of registered notification 'postgres' targets1143func GetNotifyPostgres(postgresKVS map[string]config.KVS) (map[string]target.PostgreSQLArgs, error) {1144 psqlTargets := make(map[string]target.PostgreSQLArgs)1145 for k, kv := range mergeTargets(postgresKVS, target.EnvPostgresEnable, DefaultPostgresKVS) {1146 enableEnv := target.EnvPostgresEnable1147 if k != config.Default {1148 enableEnv = enableEnv + config.Default + k1149 }1150 enabled, err := config.ParseBool(env.Get(enableEnv, kv.Get(config.Enable)))1151 if err != nil {1152 return nil, err1153 }1154 if !enabled {1155 continue1156 }1157 queueLimitEnv := target.EnvPostgresQueueLimit1158 if k != config.Default {1159 queueLimitEnv = queueLimitEnv + config.Default + k1160 }1161 queueLimit, err := strconv.Atoi(env.Get(queueLimitEnv, kv.Get(target.PostgresQueueLimit)))1162 if err != nil {1163 return nil, err1164 }1165 formatEnv := target.EnvPostgresFormat1166 if k != config.Default {1167 formatEnv = formatEnv + config.Default + k1168 }1169 connectionStringEnv := target.EnvPostgresConnectionString1170 if k != config.Default {1171 connectionStringEnv = connectionStringEnv + config.Default + k1172 }1173 tableEnv := target.EnvPostgresTable1174 if k != config.Default {1175 tableEnv = tableEnv + config.Default + k1176 }1177 queueDirEnv := target.EnvPostgresQueueDir1178 if k != config.Default {1179 queueDirEnv = queueDirEnv + config.Default + k1180 }1181 maxOpenConnectionsEnv := target.EnvPostgresMaxOpenConnections1182 if k != config.Default {1183 maxOpenConnectionsEnv = maxOpenConnectionsEnv + config.Default + k1184 }1185 maxOpenConnections, cErr := strconv.Atoi(env.Get(maxOpenConnectionsEnv, kv.Get(target.PostgresMaxOpenConnections)))1186 if cErr != nil {1187 return nil, cErr1188 }1189 psqlArgs := target.PostgreSQLArgs{1190 Enable: enabled,1191 Format: env.Get(formatEnv, kv.Get(target.PostgresFormat)),1192 ConnectionString: env.Get(connectionStringEnv, kv.Get(target.PostgresConnectionString)),1193 Table: env.Get(tableEnv, kv.Get(target.PostgresTable)),1194 QueueDir: env.Get(queueDirEnv, kv.Get(target.PostgresQueueDir)),1195 QueueLimit: uint64(queueLimit),1196 MaxOpenConnections: maxOpenConnections,1197 }1198 if err = psqlArgs.Validate(); err != nil {1199 return nil, err1200 }1201 psqlTargets[k] = psqlArgs1202 }1203 return psqlTargets, nil1204}1205// DefaultRedisKVS - default KV for redis config1206var (1207 DefaultRedisKVS = config.KVS{1208 config.KV{1209 Key: config.Enable,1210 Value: config.EnableOff,1211 },1212 config.KV{1213 Key: target.RedisFormat,1214 Value: formatNamespace,1215 },1216 config.KV{1217 Key: target.RedisAddress,1218 Value: "",1219 },1220 config.KV{1221 Key: target.RedisKey,1222 Value: "",1223 },1224 config.KV{1225 Key: target.RedisPassword,1226 Value: "",1227 },1228 config.KV{1229 Key: target.RedisQueueDir,1230 Value: "",1231 },1232 config.KV{1233 Key: target.RedisQueueLimit,1234 Value: "0",1235 },1236 }1237)1238// GetNotifyRedis - returns a map of registered notification 'redis' targets1239func GetNotifyRedis(redisKVS map[string]config.KVS) (map[string]target.RedisArgs, error) {1240 redisTargets := make(map[string]target.RedisArgs)1241 for k, kv := range mergeTargets(redisKVS, target.EnvRedisEnable, DefaultRedisKVS) {1242 enableEnv := target.EnvRedisEnable1243 if k != config.Default {1244 enableEnv = enableEnv + config.Default + k1245 }1246 enabled, err := config.ParseBool(env.Get(enableEnv, kv.Get(config.Enable)))1247 if err != nil {1248 return nil, err1249 }1250 if !enabled {1251 continue1252 }1253 addressEnv := target.EnvRedisAddress1254 if k != config.Default {1255 addressEnv = addressEnv + config.Default + k1256 }1257 addr, err := xnet.ParseHost(env.Get(addressEnv, kv.Get(target.RedisAddress)))1258 if err != nil {1259 return nil, err1260 }1261 queueLimitEnv := target.EnvRedisQueueLimit1262 if k != config.Default {1263 queueLimitEnv = queueLimitEnv + config.Default + k1264 }1265 queueLimit, err := strconv.Atoi(env.Get(queueLimitEnv, kv.Get(target.RedisQueueLimit)))1266 if err != nil {1267 return nil, err1268 }1269 formatEnv := target.EnvRedisFormat1270 if k != config.Default {1271 formatEnv = formatEnv + config.Default + k1272 }1273 passwordEnv := target.EnvRedisPassword1274 if k != config.Default {1275 passwordEnv = passwordEnv + config.Default + k1276 }1277 keyEnv := target.EnvRedisKey1278 if k != config.Default {1279 keyEnv = keyEnv + config.Default + k1280 }1281 queueDirEnv := target.EnvRedisQueueDir1282 if k != config.Default {1283 queueDirEnv = queueDirEnv + config.Default + k1284 }1285 redisArgs := target.RedisArgs{1286 Enable: enabled,1287 Format: env.Get(formatEnv, kv.Get(target.RedisFormat)),1288 Addr: *addr,1289 Password: env.Get(passwordEnv, kv.Get(target.RedisPassword)),1290 Key: env.Get(keyEnv, kv.Get(target.RedisKey)),1291 QueueDir: env.Get(queueDirEnv, kv.Get(target.RedisQueueDir)),1292 QueueLimit: uint64(queueLimit),1293 }1294 if err = redisArgs.Validate(); err != nil {1295 return nil, err1296 }1297 redisTargets[k] = redisArgs1298 }1299 return redisTargets, nil1300}1301// DefaultWebhookKVS - default KV for webhook config1302var (1303 DefaultWebhookKVS = config.KVS{1304 config.KV{1305 Key: config.Enable,1306 Value: config.EnableOff,1307 },1308 config.KV{1309 Key: target.WebhookEndpoint,1310 Value: "",1311 },1312 config.KV{1313 Key: target.WebhookAuthToken,1314 Value: "",1315 },1316 config.KV{1317 Key: target.WebhookQueueLimit,1318 Value: "0",1319 },1320 config.KV{1321 Key: target.WebhookQueueDir,1322 Value: "",1323 },1324 config.KV{1325 Key: target.WebhookClientCert,1326 Value: "",1327 },1328 config.KV{1329 Key: target.WebhookClientKey,1330 Value: "",1331 },1332 }1333)1334// GetNotifyWebhook - returns a map of registered notification 'webhook' targets1335func GetNotifyWebhook(webhookKVS map[string]config.KVS, transport *http.Transport) (1336 map[string]target.WebhookArgs, error) {1337 webhookTargets := make(map[string]target.WebhookArgs)1338 for k, kv := range mergeTargets(webhookKVS, target.EnvWebhookEnable, DefaultWebhookKVS) {1339 enableEnv := target.EnvWebhookEnable1340 if k != config.Default {1341 enableEnv = enableEnv + config.Default + k1342 }1343 enabled, err := config.ParseBool(env.Get(enableEnv, kv.Get(config.Enable)))1344 if err != nil {1345 return nil, err1346 }1347 if !enabled {1348 continue1349 }1350 urlEnv := target.EnvWebhookEndpoint1351 if k != config.Default {1352 urlEnv = urlEnv + config.Default + k1353 }1354 url, err := xnet.ParseHTTPURL(env.Get(urlEnv, kv.Get(target.WebhookEndpoint)))1355 if err != nil {1356 return nil, err1357 }1358 queueLimitEnv := target.EnvWebhookQueueLimit1359 if k != config.Default {1360 queueLimitEnv = queueLimitEnv + config.Default + k1361 }1362 queueLimit, err := strconv.Atoi(env.Get(queueLimitEnv, kv.Get(target.WebhookQueueLimit)))1363 if err != nil {1364 return nil, err1365 }1366 queueDirEnv := target.EnvWebhookQueueDir1367 if k != config.Default {1368 queueDirEnv = queueDirEnv + config.Default + k1369 }1370 authEnv := target.EnvWebhookAuthToken1371 if k != config.Default {1372 authEnv = authEnv + config.Default + k1373 }1374 clientCertEnv := target.EnvWebhookClientCert1375 if k != config.Default {1376 clientCertEnv = clientCertEnv + config.Default + k1377 }1378 clientKeyEnv := target.EnvWebhookClientKey1379 if k != config.Default {1380 clientKeyEnv = clientKeyEnv + config.Default + k1381 }1382 webhookArgs := target.WebhookArgs{1383 Enable: enabled,1384 Endpoint: *url,1385 Transport: transport,1386 AuthToken: env.Get(authEnv, kv.Get(target.WebhookAuthToken)),1387 QueueDir: env.Get(queueDirEnv, kv.Get(target.WebhookQueueDir)),1388 QueueLimit: uint64(queueLimit),1389 ClientCert: env.Get(clientCertEnv, kv.Get(target.WebhookClientCert)),1390 ClientKey: env.Get(clientKeyEnv, kv.Get(target.WebhookClientKey)),1391 }1392 if err = webhookArgs.Validate(); err != nil {1393 return nil, err1394 }1395 webhookTargets[k] = webhookArgs1396 }1397 return webhookTargets, nil1398}1399// DefaultESKVS - default KV config for Elasticsearch target1400var (1401 DefaultESKVS = config.KVS{1402 config.KV{1403 Key: config.Enable,1404 Value: config.EnableOff,1405 },1406 config.KV{1407 Key: target.ElasticURL,1408 Value: "",1409 },1410 config.KV{1411 Key: target.ElasticFormat,1412 Value: formatNamespace,1413 },1414 config.KV{1415 Key: target.ElasticIndex,1416 Value: "",1417 },1418 config.KV{1419 Key: target.ElasticQueueDir,1420 Value: "",1421 },1422 config.KV{1423 Key: target.ElasticQueueLimit,1424 Value: "0",1425 },1426 config.KV{1427 Key: target.ElasticUsername,1428 Value: "",1429 },1430 config.KV{1431 Key: target.ElasticPassword,1432 Value: "",1433 },1434 }1435)1436// GetNotifyES - returns a map of registered notification 'elasticsearch' targets1437func GetNotifyES(esKVS map[string]config.KVS, transport *http.Transport) (map[string]target.ElasticsearchArgs, error) {1438 esTargets := make(map[string]target.ElasticsearchArgs)1439 for k, kv := range mergeTargets(esKVS, target.EnvElasticEnable, DefaultESKVS) {1440 enableEnv := target.EnvElasticEnable1441 if k != config.Default {1442 enableEnv = enableEnv + config.Default + k1443 }1444 enabled, err := config.ParseBool(env.Get(enableEnv, kv.Get(config.Enable)))1445 if err != nil {1446 return nil, err1447 }1448 if !enabled {1449 continue1450 }1451 urlEnv := target.EnvElasticURL1452 if k != config.Default {1453 urlEnv = urlEnv + config.Default + k1454 }1455 url, err := xnet.ParseHTTPURL(env.Get(urlEnv, kv.Get(target.ElasticURL)))1456 if err != nil {1457 return nil, err1458 }1459 queueLimitEnv := target.EnvElasticQueueLimit1460 if k != config.Default {1461 queueLimitEnv = queueLimitEnv + config.Default + k1462 }1463 queueLimit, err := strconv.Atoi(env.Get(queueLimitEnv, kv.Get(target.ElasticQueueLimit)))1464 if err != nil {1465 return nil, err1466 }1467 formatEnv := target.EnvElasticFormat1468 if k != config.Default {1469 formatEnv = formatEnv + config.Default + k1470 }1471 indexEnv := target.EnvElasticIndex1472 if k != config.Default {1473 indexEnv = indexEnv + config.Default + k1474 }1475 queueDirEnv := target.EnvElasticQueueDir1476 if k != config.Default {1477 queueDirEnv = queueDirEnv + config.Default + k1478 }1479 usernameEnv := target.EnvElasticUsername1480 if k != config.Default {1481 usernameEnv = usernameEnv + config.Default + k1482 }1483 passwordEnv := target.EnvElasticPassword1484 if k != config.Default {1485 passwordEnv = passwordEnv + config.Default + k1486 }1487 esArgs := target.ElasticsearchArgs{1488 Enable: enabled,1489 Format: env.Get(formatEnv, kv.Get(target.ElasticFormat)),1490 URL: *url,1491 Index: env.Get(indexEnv, kv.Get(target.ElasticIndex)),1492 QueueDir: env.Get(queueDirEnv, kv.Get(target.ElasticQueueDir)),1493 QueueLimit: uint64(queueLimit),1494 Transport: transport,1495 Username: env.Get(usernameEnv, kv.Get(target.ElasticUsername)),1496 Password: env.Get(passwordEnv, kv.Get(target.ElasticPassword)),1497 }1498 if err = esArgs.Validate(); err != nil {1499 return nil, err1500 }1501 esTargets[k] = esArgs1502 }1503 return esTargets, nil1504}1505// DefaultAMQPKVS - default KV for AMQP config1506var (1507 DefaultAMQPKVS = config.KVS{1508 config.KV{1509 Key: config.Enable,1510 Value: config.EnableOff,1511 },1512 config.KV{1513 Key: target.AmqpURL,1514 Value: "",1515 },1516 config.KV{1517 Key: target.AmqpExchange,1518 Value: "",1519 },1520 config.KV{1521 Key: target.AmqpExchangeType,1522 Value: "",1523 },1524 config.KV{1525 Key: target.AmqpRoutingKey,1526 Value: "",1527 },1528 config.KV{1529 Key: target.AmqpMandatory,1530 Value: config.EnableOff,1531 },1532 config.KV{1533 Key: target.AmqpDurable,1534 Value: config.EnableOff,1535 },1536 config.KV{1537 Key: target.AmqpNoWait,1538 Value: config.EnableOff,1539 },1540 config.KV{1541 Key: target.AmqpInternal,1542 Value: config.EnableOff,1543 },1544 config.KV{1545 Key: target.AmqpAutoDeleted,1546 Value: config.EnableOff,1547 },1548 config.KV{1549 Key: target.AmqpDeliveryMode,1550 Value: "0",1551 },1552 config.KV{1553 Key: target.AmqpQueueLimit,1554 Value: "0",1555 },1556 config.KV{1557 Key: target.AmqpQueueDir,1558 Value: "",1559 },1560 }1561)1562// GetNotifyAMQP - returns a map of registered notification 'amqp' targets1563func GetNotifyAMQP(amqpKVS map[string]config.KVS) (map[string]target.AMQPArgs, error) {1564 amqpTargets := make(map[string]target.AMQPArgs)1565 for k, kv := range mergeTargets(amqpKVS, target.EnvAMQPEnable, DefaultAMQPKVS) {1566 enableEnv := target.EnvAMQPEnable1567 if k != config.Default {1568 enableEnv = enableEnv + config.Default + k1569 }1570 enabled, err := config.ParseBool(env.Get(enableEnv, kv.Get(config.Enable)))1571 if err != nil {1572 return nil, err1573 }1574 if !enabled {1575 continue1576 }1577 urlEnv := target.EnvAMQPURL1578 if k != config.Default {1579 urlEnv = urlEnv + config.Default + k1580 }1581 url, err := xnet.ParseURL(env.Get(urlEnv, kv.Get(target.AmqpURL)))1582 if err != nil {1583 return nil, err1584 }1585 deliveryModeEnv := target.EnvAMQPDeliveryMode1586 if k != config.Default {1587 deliveryModeEnv = deliveryModeEnv + config.Default + k1588 }1589 deliveryMode, err := strconv.Atoi(env.Get(deliveryModeEnv, kv.Get(target.AmqpDeliveryMode)))1590 if err != nil {1591 return nil, err1592 }1593 exchangeEnv := target.EnvAMQPExchange1594 if k != config.Default {1595 exchangeEnv = exchangeEnv + config.Default + k1596 }1597 routingKeyEnv := target.EnvAMQPRoutingKey1598 if k != config.Default {1599 routingKeyEnv = routingKeyEnv + config.Default + k1600 }1601 exchangeTypeEnv := target.EnvAMQPExchangeType1602 if k != config.Default {1603 exchangeTypeEnv = exchangeTypeEnv + config.Default + k1604 }1605 mandatoryEnv := target.EnvAMQPMandatory1606 if k != config.Default {1607 mandatoryEnv = mandatoryEnv + config.Default + k1608 }1609 immediateEnv := target.EnvAMQPImmediate1610 if k != config.Default {1611 immediateEnv = immediateEnv + config.Default + k1612 }1613 durableEnv := target.EnvAMQPDurable1614 if k != config.Default {1615 durableEnv = durableEnv + config.Default + k1616 }1617 internalEnv := target.EnvAMQPInternal1618 if k != config.Default {1619 internalEnv = internalEnv + config.Default + k1620 }1621 noWaitEnv := target.EnvAMQPNoWait1622 if k != config.Default {1623 noWaitEnv = noWaitEnv + config.Default + k1624 }1625 autoDeletedEnv := target.EnvAMQPAutoDeleted1626 if k != config.Default {1627 autoDeletedEnv = autoDeletedEnv + config.Default + k1628 }1629 queueDirEnv := target.EnvAMQPQueueDir1630 if k != config.Default {1631 queueDirEnv = queueDirEnv + config.Default + k1632 }1633 queueLimitEnv := target.EnvAMQPQueueLimit1634 if k != config.Default {1635 queueLimitEnv = queueLimitEnv + config.Default + k1636 }1637 queueLimit, err := strconv.ParseUint(env.Get(queueLimitEnv, kv.Get(target.AmqpQueueLimit)), 10, 64)1638 if err != nil {1639 return nil, err1640 }1641 amqpArgs := target.AMQPArgs{1642 Enable: enabled,1643 URL: *url,1644 Exchange: env.Get(exchangeEnv, kv.Get(target.AmqpExchange)),1645 RoutingKey: env.Get(routingKeyEnv, kv.Get(target.AmqpRoutingKey)),1646 ExchangeType: env.Get(exchangeTypeEnv, kv.Get(target.AmqpExchangeType)),1647 DeliveryMode: uint8(deliveryMode),1648 Mandatory: env.Get(mandatoryEnv, kv.Get(target.AmqpMandatory)) == config.EnableOn,1649 Immediate: env.Get(immediateEnv, kv.Get(target.AmqpImmediate)) == config.EnableOn,1650 Durable: env.Get(durableEnv, kv.Get(target.AmqpDurable)) == config.EnableOn,1651 Internal: env.Get(internalEnv, kv.Get(target.AmqpInternal)) == config.EnableOn,1652 NoWait: env.Get(noWaitEnv, kv.Get(target.AmqpNoWait)) == config.EnableOn,1653 AutoDeleted: env.Get(autoDeletedEnv, kv.Get(target.AmqpAutoDeleted)) == config.EnableOn,1654 QueueDir: env.Get(queueDirEnv, kv.Get(target.AmqpQueueDir)),1655 QueueLimit: queueLimit,1656 }1657 if err = amqpArgs.Validate(); err != nil {1658 return nil, err1659 }1660 amqpTargets[k] = amqpArgs1661 }1662 return amqpTargets, nil1663}...

Full Screen

Full Screen

bucket-targets.go

Source:bucket-targets.go Github

copy

Full Screen

...99 }100 if !globalBucketVersioningSys.Enabled(bucket) {101 return BucketReplicationSourceNotVersioned{Bucket: bucket}102 }103 vcfg, err := clnt.GetBucketVersioning(ctx, tgt.TargetBucket)104 if err != nil {105 return BucketRemoteConnectionErr{Bucket: tgt.TargetBucket}106 }107 if vcfg.Status != string(versioning.Enabled) {108 return BucketRemoteTargetNotVersioned{Bucket: tgt.TargetBucket}109 }110 }111 if tgt.Type == madmin.ILMService {112 if globalBucketVersioningSys.Enabled(bucket) {113 vcfg, err := clnt.GetBucketVersioning(ctx, tgt.TargetBucket)114 if err != nil {115 if minio.ToErrorResponse(err).Code == "NoSuchBucket" {116 return BucketRemoteTargetNotFound{Bucket: tgt.TargetBucket}117 }118 return BucketRemoteConnectionErr{Bucket: tgt.TargetBucket}119 }120 if vcfg.Status != string(versioning.Enabled) {121 return BucketRemoteTargetNotVersioned{Bucket: tgt.TargetBucket}122 }123 }124 }125 sys.Lock()126 defer sys.Unlock()127 tgts := sys.targetsMap[bucket]128 newtgts := make([]madmin.BucketTarget, len(tgts))129 labels := make(map[string]struct{}, len(tgts))130 found := false131 for idx, t := range tgts {132 labels[t.Label] = struct{}{}133 if t.Type == tgt.Type {134 if t.Arn == tgt.Arn && !update {135 return BucketRemoteAlreadyExists{Bucket: t.TargetBucket}136 }137 if t.Label == tgt.Label && !update {138 return BucketRemoteLabelInUse{Bucket: t.TargetBucket}139 }140 newtgts[idx] = *tgt141 found = true142 continue143 }144 newtgts[idx] = t145 }146 if _, ok := labels[tgt.Label]; ok && !update {147 return BucketRemoteLabelInUse{Bucket: tgt.TargetBucket}148 }149 if !found && !update {150 newtgts = append(newtgts, *tgt)151 }152 sys.targetsMap[bucket] = newtgts153 sys.arnRemotesMap[tgt.Arn] = clnt154 return nil155}156// RemoveTarget - removes a remote bucket target for this source bucket.157func (sys *BucketTargetSys) RemoveTarget(ctx context.Context, bucket, arnStr string) error {158 if globalIsGateway {159 return nil160 }161 if arnStr == "" {162 return BucketRemoteArnInvalid{Bucket: bucket}163 }164 arn, err := madmin.ParseARN(arnStr)165 if err != nil {166 return BucketRemoteArnInvalid{Bucket: bucket}167 }168 if arn.Type == madmin.ReplicationService {169 if !globalIsErasure {170 return NotImplemented{}171 }172 // reject removal of remote target if replication configuration is present173 rcfg, err := getReplicationConfig(ctx, bucket)174 if err == nil && rcfg.RoleArn == arnStr {175 if _, ok := sys.arnRemotesMap[arnStr]; ok {176 return BucketRemoteRemoveDisallowed{Bucket: bucket}177 }178 }179 }180 if arn.Type == madmin.ILMService {181 // reject removal of remote target if lifecycle transition uses this arn182 config, err := globalBucketMetadataSys.GetLifecycleConfig(bucket)183 if err == nil && transitionSCInUse(ctx, config, bucket, arnStr) {184 if _, ok := sys.arnRemotesMap[arnStr]; ok {185 return BucketRemoteRemoveDisallowed{Bucket: bucket}186 }187 }188 }189 // delete ARN type from list of matching targets190 sys.Lock()191 defer sys.Unlock()192 found := false193 tgts, ok := sys.targetsMap[bucket]194 if !ok {195 return BucketRemoteTargetNotFound{Bucket: bucket}196 }197 targets := make([]madmin.BucketTarget, 0, len(tgts))198 for _, tgt := range tgts {199 if tgt.Arn != arnStr {200 targets = append(targets, tgt)201 continue202 }203 found = true204 }205 if !found {206 return BucketRemoteTargetNotFound{Bucket: bucket}207 }208 sys.targetsMap[bucket] = targets209 delete(sys.arnRemotesMap, arnStr)210 return nil211}212// GetRemoteTargetClient returns minio-go client for replication target instance213func (sys *BucketTargetSys) GetRemoteTargetClient(ctx context.Context, arn string) *TargetClient {214 sys.RLock()215 defer sys.RUnlock()216 return sys.arnRemotesMap[arn]217}218// GetRemoteTargetWithLabel returns bucket target given a target label219func (sys *BucketTargetSys) GetRemoteTargetWithLabel(ctx context.Context, bucket, targetLabel string) *madmin.BucketTarget {220 sys.RLock()221 defer sys.RUnlock()222 for _, t := range sys.targetsMap[bucket] {223 if strings.ToUpper(t.Label) == strings.ToUpper(targetLabel) {224 tgt := t.Clone()225 return &tgt226 }227 }228 return nil229}230// GetRemoteArnWithLabel returns bucket target's ARN given its target label231func (sys *BucketTargetSys) GetRemoteArnWithLabel(ctx context.Context, bucket, tgtLabel string) *madmin.ARN {232 tgt := sys.GetRemoteTargetWithLabel(ctx, bucket, tgtLabel)233 if tgt == nil {234 return nil235 }236 arn, err := madmin.ParseARN(tgt.Arn)237 if err != nil {238 return nil239 }240 return arn241}242// GetRemoteLabelWithArn returns a bucket target's label given its ARN243func (sys *BucketTargetSys) GetRemoteLabelWithArn(ctx context.Context, bucket, arnStr string) string {244 sys.RLock()245 defer sys.RUnlock()246 for _, t := range sys.targetsMap[bucket] {247 if t.Arn == arnStr {248 return t.Label249 }250 }251 return ""252}253// NewBucketTargetSys - creates new replication system.254func NewBucketTargetSys() *BucketTargetSys {255 return &BucketTargetSys{256 arnRemotesMap: make(map[string]*TargetClient),257 targetsMap: make(map[string][]madmin.BucketTarget),258 }259}260// Init initializes the bucket targets subsystem for buckets which have targets configured.261func (sys *BucketTargetSys) Init(ctx context.Context, buckets []BucketInfo, objAPI ObjectLayer) error {262 if objAPI == nil {263 return errServerNotInitialized264 }265 // In gateway mode, bucket targets is not supported.266 if globalIsGateway {267 return nil268 }269 // Load bucket targets once during boot in background.270 go sys.load(ctx, buckets, objAPI)271 return nil272}273// UpdateAllTargets updates target to reflect metadata updates274func (sys *BucketTargetSys) UpdateAllTargets(bucket string, tgts *madmin.BucketTargets) {275 if sys == nil {276 return277 }278 sys.Lock()279 defer sys.Unlock()280 if tgts == nil || tgts.Empty() {281 // remove target and arn association282 if tgts, ok := sys.targetsMap[bucket]; ok {283 for _, t := range tgts {284 delete(sys.arnRemotesMap, t.Arn)285 }286 }287 delete(sys.targetsMap, bucket)288 return289 }290 if len(tgts.Targets) > 0 {291 sys.targetsMap[bucket] = tgts.Targets292 }293 for _, tgt := range tgts.Targets {294 tgtClient, err := sys.getRemoteTargetClient(&tgt)295 if err != nil {296 continue297 }298 sys.arnRemotesMap[tgt.Arn] = tgtClient299 }300 sys.targetsMap[bucket] = tgts.Targets301}302// create minio-go clients for buckets having remote targets303func (sys *BucketTargetSys) load(ctx context.Context, buckets []BucketInfo, objAPI ObjectLayer) {304 for _, bucket := range buckets {305 cfg, err := globalBucketMetadataSys.GetBucketTargetsConfig(bucket.Name)306 if err != nil {307 continue308 }309 if cfg == nil || cfg.Empty() {310 continue311 }312 if len(cfg.Targets) > 0 {313 sys.targetsMap[bucket.Name] = cfg.Targets314 }315 for _, tgt := range cfg.Targets {316 tgtClient, err := sys.getRemoteTargetClient(&tgt)317 if err != nil {318 continue319 }...

Full Screen

Full Screen

node_read.go

Source:node_read.go Github

copy

Full Screen

...35// newNodeR creates a new instance of nodeR.36func newNodeR() *nodeR {37 return &nodeR{}38}39// GetKey returns the key associated with the node.40func (node *nodeR) GetKey() string {41 return node.key42}43// GetLabel returns the label associated with this node.44func (node *nodeR) GetLabel() string {45 return node.label46}47// GetValue returns the value associated with the node.48func (node *nodeR) GetValue() proto.Message {49 return node.value50}51// GetFlag returns reference to the given flag or nil if the node doesn't have52// this flag associated.53func (node *nodeR) GetFlag(flagIndex int) Flag {54 return node.flags[flagIndex]55}56// GetMetadata returns the value metadata associated with the node.57func (node *nodeR) GetMetadata() interface{} {58 return node.metadata59}60// GetTargets returns a set of nodes, indexed by relation labels, that the61// edges of the given relation points to.62func (node *nodeR) GetTargets(relation string) (runtimeTargets RuntimeTargets) {63 for i := node.targets.RelationBegin(relation); i < len(node.targets); i++ {64 if node.targets[i].Relation != relation {65 break66 }67 var nodes []Node68 for _, key := range node.targets[i].MatchingKeys.Iterate() {69 nodes = append(nodes, node.graph.nodes[key])70 }71 runtimeTargets = append(runtimeTargets, RuntimeTarget{72 Label: node.targets[i].Label,73 Nodes: nodes,74 })75 }76 return runtimeTargets77}78// IterTargets allows to iterate over the set of nodes that the edges of the given79// relation points to.80func (node *nodeR) IterTargets(relation string, callback TargetIterator) {81 for i := node.targets.RelationBegin(relation); i < len(node.targets); i++ {82 if node.targets[i].Relation != relation {83 break84 }85 for _, key := range node.targets[i].MatchingKeys.Iterate() {86 skipLabel, abort := callback(node.graph.nodes[key], node.targets[i].Label)87 if abort {88 return89 }90 if skipLabel {91 // no more targets from this label to iterate through92 // (just the closing nil one)93 break94 }95 }96 // mark the end of the targets for the given label with nil target97 _, abort := callback(nil, node.targets[i].Label)98 if abort {99 return100 }101 }102}103// GetSources returns edges pointing to this node in the reverse104// orientation.105func (node *nodeR) GetSources(relation string) (runtimeTargets RuntimeTargets) {106 for i := node.sources.RelationBegin(relation); i < len(node.sources); i++ {107 if node.sources[i].Relation != relation {108 break109 }110 var nodes []Node111 for _, key := range node.sources[i].MatchingKeys.Iterate() {112 nodes = append(nodes, node.graph.nodes[key])113 }114 runtimeTargets = append(runtimeTargets, RuntimeTarget{115 Label: node.sources[i].Label,116 Nodes: nodes,117 })118 }119 return runtimeTargets...

Full Screen

Full Screen

Get

Using AI Code Generation

copy

Full Screen

1import "fmt"2func main(){3 t.Get(1)4 t.Get(2)5 t.Get(3)6 t.Get(4)7 t.Get(5)8 t.Get(6)9 t.Get(7)10 t.Get(8)11 t.Get(9)12 t.Get(10)13 t.Get(11)14 t.Get(12)15 t.Get(13)16 t.Get(14)17 t.Get(15)18 t.Get(16)19 t.Get(17)20 t.Get(18)21 t.Get(19)22 t.Get(20)23 t.Get(21)24 t.Get(22)25 t.Get(23)26 t.Get(24)27 t.Get(25)28 t.Get(26)29 t.Get(27)30 t.Get(28)31 t.Get(29)32 t.Get(30)33 t.Get(31)34 t.Get(32)35 t.Get(33)36 t.Get(34)37 t.Get(35)38 t.Get(36)39 t.Get(37)40 t.Get(38)41 t.Get(39)42 t.Get(40)43 t.Get(41)44 t.Get(42)45 t.Get(43)46 t.Get(44)47 t.Get(45)48 t.Get(46)49 t.Get(47)50 t.Get(48)51 t.Get(49)52 t.Get(50)53 t.Get(51)54 t.Get(52)55 t.Get(53)56 t.Get(54)57 t.Get(55)58 t.Get(56)59 t.Get(57)60 t.Get(58)61 t.Get(59)62 t.Get(60)63 t.Get(61)64 t.Get(62)65 t.Get(63)66 t.Get(64)67 t.Get(65)68 t.Get(66)69 t.Get(67)70 t.Get(68)71 t.Get(69)72 t.Get(70)73 t.Get(71)74 t.Get(72)75 t.Get(73)76 t.Get(74)77 t.Get(75)78 t.Get(76)79 t.Get(77)80 t.Get(78)81 t.Get(79)82 t.Get(80)

Full Screen

Full Screen

Get

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 x := targets.Get()4 fmt.Println(x)5}6func Get() string {7}8import (9func TestGet(t *testing.T) {10 if Get() != "Hello, world." {11 t.Error("Expected 'Hello, world.'")12 }13}14import "testing"15func BenchmarkGet(b *testing.B) {16 for i := 0; i < b.N; i++ {17 Get()18 }19}20import (21func ExampleGet() {22 fmt.Println(Get())23}24import (25func TestGet(t *testing.T) {26 if Get() != "Hello, world." {27 t.Error("Expected 'Hello, world.'")28 }29}30import "testing"31func BenchmarkGet(b *testing.B) {32 for i := 0; i < b.N; i++ {33 Get()34 }35}36import (37func ExampleGet() {38 fmt.Println(Get())39}40import (41func TestGet(t *testing.T) {42 if Get() != "Hello, world." {43 t.Error("Expected 'Hello, world.'")44 }45}46import "testing"47func BenchmarkGet(b *testing.B) {48 for i := 0; i < b.N; i++ {49 Get()50 }51}

Full Screen

Full Screen

Get

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println(targets.Get())4}5import (6func main() {7 fmt.Println(targets.Get())8}9func Get() string {10}11import (12func main() {13 fmt.Println(targets.Get())14}15func Get() string {16}

Full Screen

Full Screen

Get

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 fmt.Println("Hello, playground")4 t.Get()5}6import (7func main() {8 fmt.Println("Hello, playground")9 t.Get()10}11import (12func main() {13 fmt.Println("Hello, playground")14 t.Get()15}16import (17func main() {18 fmt.Println("Hello, playground")19 t.Get()20}21import (22func main() {23 fmt.Println("Hello, playground")24 t.Get()25}26import (27func main() {28 fmt.Println("Hello, playground")29 t.Get()30}31import (32func main() {33 fmt.Println("Hello, playground")34 t.Get()35}36import (37func main() {38 fmt.Println("Hello, playground")39 t.Get()40}41import (42func main() {43 fmt.Println("Hello, playground")44 t.Get()45}46import (47func main() {

Full Screen

Full Screen

Get

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 start := time.Now()4 for i := 1; i <= 10; i++ {5 if err != nil {6 panic(err)7 }8 defer resp.Body.Close()9 body, err := ioutil.ReadAll(resp.Body)10 if err != nil {11 panic(err)12 }13 var dat map[string]interface{}14 if err := json.Unmarshal(body, &dat); err != nil {15 panic(err)16 }17 fmt.Println(dat)18 }19 elapsed := time.Since(start)20 fmt.Println("Time taken : ", elapsed)21}22import (23func main() {24 start := time.Now()25 for i := 1; i <= 10; i++ {26 if err != nil {27 panic(err)28 }29 defer resp.Body.Close()30 body, err := ioutil.ReadAll(resp.Body)31 if err != nil {32 panic(err)33 }34 var dat map[string]interface{}35 if err := json.Unmarshal(body, &dat); err != nil {36 panic(err)37 }38 fmt.Println(dat)39 }40 elapsed := time.Since(start)41 fmt.Println("Time taken : ", elapsed)42}43import (44func main() {45 start := time.Now()46 for i := 1; i <= 10; i++ {47 if err != nil {48 panic(err)49 }50 defer resp.Body.Close()51 body, err := ioutil.ReadAll(resp.Body)52 if err != nil {53 panic(err)54 }55 var dat map[string]interface{}

Full Screen

Full Screen

Get

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 targets.Get()4 fmt.Println(targets)5}6import (7func main() {8 targets.Add()9 fmt.Println(targets)10}11import (12func main() {13 targets.Delete()14 fmt.Println(targets)15}16import (17func main() {18 targets.Update()19 fmt.Println(targets)20}21import (22func main() {23 targets.Get()24 fmt.Println(targets)25}26import (27func main() {28 targets.Add()29 fmt.Println(targets)30}31import (32func main() {33 targets.Delete()34 fmt.Println(targets)35}36import (37func main() {38 targets.Update()39 fmt.Println(targets)40}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful