Best Rod code snippet using utils.Println
core.go
Source:core.go
...44 ssdbClients []*ssdb.SSDBClient, reqChannel *amqp.Channel,45 respChannel *amqp.Channel, crawlerName string, respQueueName string) error {46 resp, err := local_http.Send(proxyClient, req, httpClient)47 if err != nil {48 utils.Info.Println("http Send fail", crawlerName, err.Error(), resp.HttpProxy)49 // Remove http_proxy in redis to improve proxy quality.50 if resp.HttpProxy != "" {51 p := pureProxy(resp.HttpProxy)52 utils.Info.Println("delete proxy ", p)53 err = proxy.Delete(proxyClient, p, req.ProxyName)54 if err != nil {55 utils.Error.Println("delete proxy fail", err.Error())56 }57 }58 return request.Done(reqChannel, req, false)59 }60 err = response.Push(ssdbClients, resp)61 if err != nil {62 utils.Error.Println("response Push fail", crawlerName, err.Error())63 return request.Done(reqChannel, req, false)64 }65 err = response.PushKey(respChannel, resp, respQueueName)66 if err != nil {67 utils.Error.Println("response PushKey fail", crawlerName, err.Error())68 return request.Done(reqChannel, req, false)69 }70 return request.Done(reqChannel, req, true)71}72func consumer(73 c *core_consumer.CoreConsumer,74 connPool *rabbitmq.ConnPool,75 ssdbClients []*ssdb.SSDBClient,76 httpClient *http.Client,77 proxyClient *ssdb.ProxyClient) {78 defer core_consumer.ExitCoreConsumer(c)79 utils.Info.Printf("[%s] start consumer", c.CrawlerName)80 conn := connPool.Get().(*amqp.Connection)81 connPool.Release(conn)82 reqChannel, err := conn.Channel()83 if err != nil {84 utils.Error.Println("request MakeChannel fail and exit ", c.CrawlerName, err.Error())85 return86 } else {87 utils.Info.Println(c.CrawlerName, "request MakeChannel ok")88 }89 defer reqChannel.Close()90 err = reqChannel.Qos(30, 0, false)91 if err != nil {92 utils.Error.Println("request channel Qos fail and exit", c.CrawlerName, err.Error())93 return94 }95 respChannel, err := conn.Channel()96 respChannel.Confirm(false)97 if err != nil {98 utils.Error.Println("response MakeChannel fail and exit ", c.CrawlerName, err.Error())99 return100 } else {101 utils.Info.Println(c.CrawlerName, "response MakeChannel ok")102 }103 defer respChannel.Close()104 deliveries, err := request.Consume(reqChannel, c.ReqQueue)105 if err != nil {106 utils.Error.Println("request Consume fail: ", c)107 return108 }109 ticker := time.NewTicker(5 * time.Second)110 for {111 select {112 case <-ticker.C:113 utils.Debug.Println("check channel status", c.CrawlerName, c.ReqQueue, c.RespQueue)114 q, err := reqChannel.QueueInspect(c.ReqQueue)115 if err != nil {116 utils.Info.Println(c.CrawlerName, "QueueInspect fail", err.Error())117 return118 } else if err == nil && q.Messages == 0 {119 utils.Info.Println("QueueInspect empty and exit")120 return121 } else {122 utils.Debug.Println("QueueInspect success", c)123 }124 q, err = respChannel.QueueInspect(c.RespQueue)125 if err != nil {126 utils.Info.Println(c.CrawlerName, "RespQueue QueueInspect fail", err.Error())127 return128 } else {129 utils.Debug.Println("QueueInspect success", c)130 }131 case d := <-deliveries:132 req, err := request.Get(d)133 if err == nil && req == nil {134 utils.Info.Printf("[%s]consumer Get Delivery empty\n", c.CrawlerName)135 _, err = reqChannel.QueueInspect(c.ReqQueue)136 if err != nil {137 utils.Info.Println(c.CrawlerName, "QueueInspect fail", err.Error())138 return139 } else {140 time.Sleep(1 * time.Second)141 }142 continue143 }144 if err != nil {145 utils.Info.Printf("[%s]request Get deliveries error: %s\n", c.CrawlerName, string(d.Body))146 } else {147 utils.Debug.Println("consume ", req.Url)148 go consume(httpClient, proxyClient, req, ssdbClients, reqChannel, respChannel, c.CrawlerName, c.RespQueue)149 }150 default:151 utils.Debug.Println("coming to default operation", c)152 time.Sleep(10 * time.Millisecond)153 }154 }155}156func cleanup(cfg config.Config, proxyClient *ssdb.ProxyClient) {157 proxyClient.ConnPool.Close()158 utils.Info.Printf("process exit")159}160func run(cfgFile string, consumerNumber int, crawlerName string) {161 var conn *amqp.Connection162 var consumers []*core_consumer.CoreConsumer163 cfg, err := config.Get(cfgFile)164 if err != nil {165 utils.Error.Println("read config file fail ", err.Error(), cfgFile)166 return167 }168 proxyNode := config.SSDBNode{169 Host: cfg.ProxyRedisIp,170 Port: cfg.ProxyRedisPort,171 }172 ssdbNodes := cfg.SSDBNodes173 if len(ssdbNodes) == 0 {174 utils.Error.Println("ssdb nodes can not be empty")175 return176 }177 ssdbClients := ssdb.GetClients(ssdbNodes, cfg, ssdb.Params{MaxIdle: 5000, MaxActive: 5000})178 proxyClient := ssdb.GetProxyClient(proxyNode, ssdb.Params{MaxIdle: 5000, MaxActive: 5000})179 connPool := &rabbitmq.ConnPool{180 MaxIdle: 10,181 MaxActive: 50,182 Dial: rabbitmq.CreateConn,183 Cfg: cfg,184 }185 maxConn := 1000186 httpClients := CrawlerHttpClients(consumerNumber, maxConn)187 sigs := make(chan os.Signal, 1)188 signal.Notify(sigs, os.Interrupt)189 signal.Notify(sigs, syscall.SIGTERM)190 go func() {191 <-sigs192 cleanup(cfg, proxyClient)193 os.Exit(0)194 }()195 for {196 reqQueues, err := core_queue.GetQueues("http_request:", cfg)197 if err != nil {198 utils.Error.Printf("GetReqQueues error:%s\n", err.Error())199 time.Sleep(1 * time.Second)200 continue201 } else {202 utils.Debug.Println("GetReqQueues success")203 }204 respQueues, err := core_queue.GetQueues("http_response:", cfg)205 if err != nil {206 utils.Error.Printf("GetRespQueues error:%s\n", err.Error())207 time.Sleep(1 * time.Second)208 continue209 } else {210 utils.Debug.Println("GetRespQueues success")211 }212 conn = connPool.Get().(*amqp.Connection)213 reqQueues, err = core_queue.UpdateQueueCount(reqQueues, conn)214 if err != nil {215 utils.Error.Println(err.Error())216 time.Sleep(1 * time.Second)217 continue218 } else {219 utils.Debug.Println("UpdateQueueCount success")220 }221 connPool.Release(conn)222 reqQueues = core_queue.RemoveEmptyQueues(reqQueues)223 utils.Debug.Println(reqQueues)224 if len(reqQueues) == 0 {225 utils.Info.Println("req queues empty")226 time.Sleep(1 * time.Second)227 continue228 } else {229 utils.Debug.Println("RemoveEmptyQueues success")230 }231 core_queue.DeclareResponseQueues(conn, reqQueues, 5)232 conn = connPool.Get().(*amqp.Connection)233 respQueues, err = core_queue.UpdateQueueCount(respQueues, conn)234 utils.Debug.Println(respQueues)235 if err != nil {236 conn = nil237 utils.Error.Println(err.Error())238 time.Sleep(1 * time.Second)239 continue240 }241 connPool.Release(conn)242 if len(respQueues) == 0 {243 utils.Info.Println("resp queues empty")244 time.Sleep(1 * time.Second)245 continue246 }247 consumers = core_consumer.AliveCrawlerConsumers(consumers, crawlerName)248 utils.Debug.Println("total consumers: ", len(consumers), ", need start consumers:", consumerNumber-len(consumers))249 newConsumers := consumerNumber - len(consumers)250 for i := 0; i < newConsumers; i++ {251 reqQueueName, err := core_queue.GetRandReqQueue(reqQueues, crawlerName)252 if err != nil {253 utils.Error.Printf(err.Error())254 continue255 }256 utils.Debug.Printf("GetRandReqQueue %s\n", reqQueueName)257 respQueueName, err := core_queue.GetRandRespQueue(respQueues, crawlerName)258 if err != nil {259 utils.Error.Printf(err.Error())260 continue261 }262 utils.Debug.Printf("GetRandRespQueue %s\n", respQueueName)263 index := i / maxConn264 c := core_consumer.CreateCoreConsumer(i, crawlerName, reqQueueName, respQueueName)265 consumers = append(consumers, c)266 utils.Debug.Println("add consumer", c)267 go consumer(c, connPool, ssdbClients, httpClients[index], proxyClient)268 }269 if len(consumers) < consumerNumber {270 utils.Warning.Printf("aliveConsumers now %d, lower than %d\n", len(consumers), consumerNumber)271 }272 utils.Debug.Println("total consumers ", len(consumers))273 time.Sleep(1 * time.Second)274 }275}276func main() {277 logLevel := flag.String("level", "info", "log level: debug, info, warning, error")278 // logFile := flag.String("log_file", "/var/log/yascrapy/core.log", "specify the output log file")279 cfgFile := flag.String("config_file", "/etc/yascrapy/core.json", "specify core downloader config file in json")280 consumers := flag.Int("consumers", 1, "specify consumers number")281 crawlerName := flag.String("crawler_name", "", "specify crawler name, can not be empty")282 flag.Parse()283 // handles, err := utils.GetHandles(*logLevel, *logFile)284 handles, err := utils.GetHandles(*logLevel)285 if err != nil {286 fmt.Println(err.Error())287 return288 }289 if *crawlerName == "" {290 fmt.Println("crawlerName can not be empty")291 return292 }293 utils.InitLoggers(handles[0], handles[1], handles[2], handles[3])294 rand.Seed(time.Now().Unix())295 run(*cfgFile, *consumers, *crawlerName)296}...
app.go
Source:app.go
...7)8func Legu(pkgName string, pkgUrl string, pkgMd5 string) {9 conf, err := utils.ReadConf()10 if err != nil {11 fmt.Println("an err occurd on read config file: ", err)12 os.Exit(1)13 }14 client, err := utils.NewMsClient(conf)15 if err != nil {16 fmt.Println("an err occurd on create ms client: ", err)17 os.Exit(1)18 }19 //shield20 fmt.Println("start shiled pkg: ", pkgName)21 waitTime := conf.Shield.ShieldTimeout22 checkInterval := conf.Shield.CheckInterval23 if waitTime == 0 {24 waitTime = 180025 }26 if checkInterval == 0 {27 checkInterval = 3028 }29 apkDlUrl, err := utils.ShieldPkg(client, pkgName, pkgUrl, pkgMd5, waitTime, checkInterval)30 if err != nil {31 fmt.Println("an err occurd on shield pkg: ", err)32 os.Exit(1)33 }34 //download35 fmt.Println("start download shield apk")36 DownloadDestApkFile, err := utils.ApkDownLoad(apkDlUrl, conf.Shield.OutDirectory)37 if err != nil {38 if DownloadDestApkFile != "" {39 _ = os.Remove(DownloadDestApkFile)40 }41 fmt.Println("an err occurd on download the shield apk file: ", err)42 os.Exit(1)43 }44 //align45 fmt.Println("align apk file")46 AlignDestPkg, err := utils.AlignApk(conf, DownloadDestApkFile)47 if err != nil {48 fmt.Println("an err occurd on align the apk file: ", err)49 os.Exit(1)50 }51 //resign52 fmt.Println("resign shield apk file")53 SignedPkg, err := utils.SignApk(conf, AlignDestPkg, true)54 if err != nil {55 fmt.Println("an err occurd on sign the apk file: ", err)56 os.Exit(1)57 }58 //handler result59 fmt.Println("Legu Shield Completion: ", SignedPkg)60}61func Sign(srcPkg string, removeAlign bool) {62 conf, err := utils.ReadConf()63 if err != nil {64 fmt.Println("an err occurd on read config file: ", err)65 os.Exit(1)66 }67 //align68 fmt.Println("align apk file")69 AlignDestPkg, err := utils.AlignApk(conf, srcPkg)70 if err != nil {71 fmt.Println("an err occurd on align the apk file: ", err)72 os.Exit(1)73 }74 //resign75 fmt.Println("resign shield apk file")76 SignedPkg, err := utils.SignApk(conf, AlignDestPkg, true)77 if err != nil {78 fmt.Println("an err occurd on sign the apk file: ", err)79 _ = os.Remove(AlignDestPkg)80 os.Exit(1)81 }82 if removeAlign {83 _ = os.Remove(AlignDestPkg)84 }85 //handler result86 fmt.Println("Sign Completion: ", SignedPkg)87}88//Check(itemId,count,interval,untilsuccess)89func Check(itemId string, count int, interval int, untilsuccess bool) {90 conf, err := utils.ReadConf()91 if err != nil {92 fmt.Println("an err occurd on read config file: ", err)93 os.Exit(1)94 }95 client, err := utils.NewMsClient(conf)96 if err != nil {97 fmt.Println("an err occurd on create ms client: ", err)98 os.Exit(1)99 }100 if untilsuccess {101 for {102 success := utils.CheckShield(client, itemId)103 if success {104 break105 }106 time.Sleep(time.Duration(interval) * time.Second)107 }108 } else {109 for i := 0; i < count; i++ {110 success := utils.CheckShield(client, itemId)111 if success {...
main.go
Source:main.go
...6 "github.com/Agaetis-IT/imerologio-cli/pkg/ime_utils"7 "github.com/cheggaaa/pb/v3"8)9func main() {10 ime_utils.PrintlnInfo("Imerologio CLI helps you bootstrap your event sourcing app easily â¨")11 answers := ime_types.Answers{}12 err := ime_survey.AskAppName(&answers)13 if err != nil {14 ime_utils.PrintlnError(err.Error())15 return16 }17 err = ime_survey.AskAppPath(&answers)18 if err != nil {19 ime_utils.PrintlnError(err.Error())20 return21 }22 err = ime_survey.AskKafka(&answers)23 if err != nil {24 ime_utils.PrintlnError(err.Error())25 return26 }27 showRecap(answers)28 beginGeneration := false29 err = ime_survey.AskBeginGeneration(&beginGeneration)30 if err != nil {31 ime_utils.PrintlnError(err.Error())32 return33 }34 if !beginGeneration {35 ime_utils.PrintlnInfo("Ok, I've done nothing. See you soon ð")36 } else {37 err = generateApp(answers)38 if err != nil {39 ime_utils.PrintlnError(err.Error())40 return41 }42 ime_utils.PrintlnInfo("Done! Happy coding ð")43 }44}45func showRecap(answers ime_types.Answers) {46 ime_utils.PrintlnInfo("")47 ime_utils.PrintlnInfo("Ok, let's recap")48 ime_generate.RecapWorkspace(answers)49 ime_generate.RecapKafka(answers)50 ime_utils.PrintlnInfo("")51}52func generateApp(answers ime_types.Answers) error {53 count := 1054 bar := pb.Simple.Start(count)55 bar.SetTemplateString(`{{string . "prefix"}}{{bar . }} {{percent . }}{{string . "suffix"}}`)56 err := ime_generate.GenerateWorkspace(bar, answers.Path)57 if err != nil {58 return err59 }60 err = ime_generate.GenerateKafka(bar, answers)61 if err != nil {62 return err63 }64 return nil...
Println
Using AI Code Generation
1import (2func main() {3 utils.Println("Hello World")4}5import "fmt"6func Println(msg string) {7 fmt.Println(msg)8}
Println
Using AI Code Generation
1import "utils"2func main() {3 utils.Println("Hello World")4}5import "fmt"6func Println(msg string) {7 fmt.Println(msg)8}
Println
Using AI Code Generation
1import (2func main() {3 fmt.Println("Hello World")4 utils.Println("Hello World")5}6import "fmt"7func Println(str string) {8 fmt.Println(str)9}
Println
Using AI Code Generation
1import (2func main() {3 utils.Println("Hello World")4}5import "fmt"6func Println(msg string) {7 fmt.Println(msg)8}9import "github.com/username/GoTest/utils"10 /usr/local/go/src/github.com/username/GoTest/utils (from $GOROOT)11 /home/username/go/src/github.com/username/GoTest/utils (from $GOPATH)12 /usr/local/go/src/github.com/username/GoTest/utils (from $GOROOT)13 /home/username/go/src/github.com/username/GoTest/utils (from $GOPATH)14How can I import the utils package in my 2.go file?
Println
Using AI Code Generation
1import "utils"2func main() {3 utils.Println("Hello World")4}5import "fmt"6func main() {7 fmt.Println("Welcome to Go")8}9import "fmt"10func main() {11 fmt.Println("Welcome to Go")12}13import "fmt"14func main() {15 fmt.Println("Welcome to Go")16}17import "fmt"18func main() {19 fmt.Println("Welcome to Go")20}21import "fmt"22func main() {23 fmt.Println(name)24}
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!