Tag:go

  • Go run main.go keeps prompting that the package solution cannot be found

    Time:2021-10-25

    As follows: ./src/github.com/sirupsen/logrus/terminal_check_notappengine.go:9:2: cannot find package “golang.org/x/crypto/ssh/terminal” in any of The corresponding package has been downloaded from githup in the corresponding path https://github.com/golang/crypto But it still prompts this error At that time, the project was running in the ~ / go directory, and the imported packages could not call each other When the project is […]

  • Your 4 misunderstandings about go error handling!

    Time:2021-10-24

    Hello, I’m fried fish. GoIn languageerror handlingThe mechanism of has always been a hot issue among gophers. It has even been hoped that go supports throw and catch keywords to achieve features similar to other languages. Discussions in the community never stopped. Today, fried fish takes you to know some problems that you are most […]

  • Go module: how to solve the reference problem of private non compliant Library

    Time:2021-10-23

    Hello, I’m polarisxu. A friend asked a question: Netizen consultation In actual projects, when using go module, it is inevitable to have some own libraries to reference. These libraries are managed by self built git services, such as gitlab. In view of this situation, many tutorials let you set goprivate, that is, do not go […]

  • Implementation of go plugins plug-in

    Time:2021-10-22

    Official implementation Golang version 1.8 and above provides a new tool for creating shared objects, called plugins. At present, plugins is only supported on Linux, FreeBSD and MacOS, and only supports golang calls. ​ Using the example, define aplugin.go : ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 […]

  • Implementation of go co process timeout control

    Time:2021-10-20

    Go co process timeout control Select blocking mode Context mode Let’s start with a scenario: Suppose that service a needs to call service B in the business and requires a 5S timeout to be set, how to implement it gracefully? Select timeout control Consider whether it can be implemented in the mode of select + […]

  • How should go implement L2 caching

    Time:2021-10-19

    1、 Demand Implement L2 cache After the program runs, it will prompt: “please enter the command:”. If you enter getall, the information of all personnel will be queried and displayed Query MySQL for the first time, cache the results in redis, and set the expiration time of 60 seconds For each subsequent query, if there […]

  • Go implements the operation of HTTP middleman proxy

    Time:2021-10-19

    goproxy Go HTTP (s) proxy library, which supports man in the middle proxy to decrypt HTTPS Project address install go get github.com/ouqiang/goproxy use package main import ( “net/http” “time” “github.com/ouqiang/goproxy” ) func main() { proxy := goproxy.New() server := &http.Server{ Addr: “:8080”, Handler: proxy, ReadTimeout: 1 * time.Minute, WriteTimeout: 1 * time.Minute, } err := […]

  • Go implementation of redis connection pool

    Time:2021-10-18

    1、 What is connection pool and what is the use of connection pool Let’s take a look at how others introduce connection pools: The basic idea of connection pool is to store the database connection as an object in memory during system initialization. When users need to access the database, they do not establish a […]

  • Solve the pit that go Gorm stepped on

    Time:2021-10-18

    Data cannot be queried after gorm.model is used Scan error on column index 1, name “created_at” Tips: Scan error on column index 1, name “created_at”: unsupported Scan, storing driver.Value type []uint8 terms of settlement: Add parsetime = true when opening the database root:[email protected](127.0.0.1:3306)/mapdb?charset=utf8&parseTime=true Supplement: Usage Summary of golang Gorm When creating a structure, you can […]

  • How to use function types in go?

    Time:2021-10-16

    = Function types is a very special type, which represents a collection of functions with the same input parameter type and return value type. The following line of code defines a function type called greeting typeGreetingfunc(namestring)string This type has two characteristics: Only one parameter is received, and the type of the parameter is string The […]

  • Method of using encryption algorithm in go

    Time:2021-10-15

    Hash algorithm  md5 128bit, 16 bytes For example: MD5 (“Hello world!”) = fc3ff98e8c6a0d3087d515c0473f8677 / / 32-bit hexadecimal digit ? 1 2 3 4 5 6 7 8 9 10 11 12 13 func Test(t *testing.T) {     //Method 1     str := “hello world!”     has := md5.Sum([]byte(str))     Md5str1: = FMT. Sprintf (‘% X’, has) // convert [] […]

  • Solve the exit problem of subprocess after go function exit

    Time:2021-10-13

    This problem comes from a test code I saw when I was reading the fabric source code. I enabled the coroutine in a function, and then the function exited. Because I haven’t handled it like this before, and affected by the original C + + function domain, I think the function exited and the sub […]