Tag:go

  • Summary of six go techniques for string processing

    Time:2020-12-1

    If you switch from ruby or Python to go, there will be a lot of language differences to learn, many of which focus on handling string types. Here are some string tricks that solved the problems I encountered in my first few weeks with golang. 1. Multi line string It’s very easy to create multiline […]

  • A hidden function of defer in go

    Time:2020-11-30

    Defer is an important feature to focus on when you start coding with go. It’s very simple: in any function, prefix the calls of other functions with defer to ensure that the function executes immediately before the external function exits, and the delayed function will run even if the external function is interrupted by an […]

  • Implementation of Gobang prediction algorithm written by go

    Time:2020-11-28

    For details, see GitHub: https://github.com/shanhuijie/GoWatch/tree/master/fiveinarow Five in a row From the horizontal, vertical, left oblique rise, left oblique down four angles const( matrix = 50*50 point = 3 ) type Coordinat struct{ x int y int } type Allinat struct{ key []Coordinat } func InArray(need Coordinat, needArr []Coordinat) bool { for _,v := range needArr{ […]

  • Several points of go using defer function

    Time:2020-11-27

    summary Everyone must have used the defer function. It will not be executed immediately when it is declared, but after the function returns. Its main application scenarios include exception handling, logging, data cleaning, resource releasing and so on. This article is not to share the application scenarios of defer, but to share the points needing […]

  • Go processing PDF implementation code

    Time:2020-11-24

    In our work, we often encounter some problems in PDF file processing. There are 1000 processing methods for a thousand kinds of PDF files. Every time we try our best to fight these PDF files to the end. I am also a gopher, so this article will list every PDF processing scenario I have experienced […]

  • Explain how to output version information in go project

    Time:2020-11-21

    When we use the CLI tool, we often have such parameter output: ➜ ~ docker version Client: Docker Engine – Community Version: 18.09.2 API version: 1.39 Go version: go1.10.8 Git commit: 6247962 Built: Sun Feb 10 04:12:39 2019 OS/Arch: darwin/amd64 Experimental: false ➜ ~ You can print the version information corresponding to the build, such […]

  • Explain the difference between make (Chan int, 1) and make (Chan int) in go language

    Time:2020-11-18

    There is a problem with golang channel: it is found that the go coprocessor does not execute cooperatively as expected when reading channel data. After checking the data: Due to improper operation of channel, there are buffers and no buffers in channel. The following is the difference between them. No buffer channel Chan created with […]

  • Implementation of Telnet echo server in go language

    Time:2020-11-17

    This paper introduces the go language telnet echo server and shares it with you. The details are as follows: package main import ( “fmt” “net” “bufio” “strings” “os” ) func main() { //Create a channel for program end code exitChan := make(chan int) //Run the server concurrently go server(“127.0.0.1:7001”, exitChan) //Channel blocked, waiting to receive […]

  • Learn how to use go reflection

    Time:2020-11-16

    What is reflection Most of the time, variables, types and functions in go are very simple and straightforward. When you need a type, variable or function, you can define them directly type Foo struct { A int B string } var x Foo func DoSomething(f Foo) { fmt.Println(f.A, f.B) } But sometimes you want to […]

  • How to use go unsafe package

    Time:2020-11-15

    Unsafe package Golang is a static strongly typed language. All types cannot be converted at will. Go language does not allow two pointer types to be converted. It is not easy to avoid the security of the program, because it is not safe to use the program. But it’s very practical in many places. In […]

  • Go verifies whether Chinese is included in the string (recommended)

    Time:2020-11-14

    When we find a method to verify whether a string contains Chinese drops, a better method than regular is found. Moreover, it is a self-contained drop verification in golang. You don’t need to write your own regular verification. The code is as follows: package main import ( “fmt” “regexp” “unicode” ) func main() { S1: […]

  • An example of implementation of markdown parsing library with go language

    Time:2020-11-7

    Blackfriday is a markdown processor implemented in go. You can input user provided data safely, fast, support universal extensions (tables, smart punctuation replacement, etc.), and it is safe input for all UTF-8 (Unicode). Currently, HTML output and smartypants extension are supported. use First of all, of course, we should introduce: import github.com/russross/blackfriday then output := […]