• An in-depth analysis of the writing method of for loop in go language


    For loop is a loop control structure, which can effectively write a specific number of loops that need to be executed. grammarThe syntax of for loop in go programming language is as follows: Copy codeThe code is as follows: for [condition |  ( init; condition; increment ) | Range] {    statement(s); } The following […]

  • Implementation example of golang progress bar function


    Recently, I’m working on a requirement. The function is very simple. It’s to develop a lightweight client to pass the content in a specified file through theTCPSend to the server. Because the file is very large, it may reach the order of 100g, so the processing will be relatively slow. In order to provide users […]

  • Three ways to declare golang variables


    There are three ways to declare variables in golang  One is to use VaR keyword to declare package level or function level variables;  The second is to use the short variable declaration method, which can only declare function level variables and need to specify the variable value;  Third, the const keyword is used to declare […]

  • Golang you must understand the connection pool implementation


    Problem introduction As a golang developer, the online environment has encountered a number of connection explosion problems (MySQL / redis / Kafka, etc.). For this reason, golang, as a resident process, needs to manually close the connection after requesting a third-party service or resource, otherwise the connection will always exist. Most of the time, developers […]

  • Sample implementation of golang HTTP captcha


    Captcha is the abbreviation of “completely automated Public Turing test to tell computers and humans apart”. It is a kind of public automatic program to distinguish whether a user is a computer or a human. Can prevent: malicious password cracking, ticket swiping, Forum irrigation, effectively prevent a hacker to a specific registered user with a […]

  • On the confusion of golang IO reading and writing


    preface There are many ways to read and write IO in golang. At present, I know IO library, OS library, ioutil library, bufio library, bytes / strings library and so on. Although kurdo is a good thing, which means more choices, what puzzles me is: which library should be used in what scenario? Why? Before […]

  • Why there is no ternary operator in golang


    Ternary operators are widely used in other languages python: val = trueValue if expr else falseValue javascript: const val = expr ? trueValue : falseValue c、c++: const char *val = expr ? “trueValue” : “falseValue”; However, the widely supported ternary operator does not exist in golang! If we write something like this: val := expr […]

  • Several points that need to be paid attention to when using map in golang


    1. Introduction Map is a convenient and powerful built-in data structure in golang. It is an unordered group of elements of the same type, and the elements are indexed by a unique key of another type. The key can be of any type supported by the equality operator, such as integer, floating-point number, complex number, […]

  • How does golang parse and generate JSON


    JSON (JavaScript object notation) is a lightweight data exchange language, which is text-based, self descriptive and easy to read. Although JSON is a subset of JavaScript, it is a language independent text format and adopts some habits similar to the C language family. The biggest difference between JSON and XML is that XML is a […]

  • Implementation of Java UUID serialization by golang


    At present, only the fixed UUID generated by Java is implemented: 85bb94b8-fd4b-4e1c-8f49-3cedd49d8f28 package main import ( “encoding/binary” “encoding/json” “fmt” “log” “os” “strings” “time” “github.com/Shopify/sarama” “github.com/google/uuid” ) const ( DATE_TIME_PATTERN = “” STREAM_MAGIC = 0xaced STREAM_VERSION = 5 TC_STRING = 0x74 TC_OBJECT = 0x73 TC_CLASSDESC = 0x72 SC_SERIALIZABLE = 0x02 TC_ENDBLOCKDATA = 0x78 TC_NULL = 0x70 […]

  • How to use channel in golang development


    Channel is an important feature of golang. It is the existence of channel that makes golang different from other languages It makes concurrent programming easy and interesting. The concept and syntax of channel A channel can be understood as a FIFO message queue. Channel is used to transfer data before goroutine. To be exact, it […]

  • Detailed explanation of select multiple selection in golang development


    Select is a control structure in golang, which is syntactically similar to switch statement, except that select is used for communication between goroutines. Each case must be a communication operation, either sending or receiving. Select will randomly execute a runnable case. If there is no case to run, goroutine will block until there is a […]