Go language | Are you still getting the file size like this?

In a project, we may need to get the size of a file. In Golang (Go language), there are many ways to get the size of a file to see if you are still using the slowest way. Read byte method The first one is the most intuitive to think of, which is to open the file and read the file again. func main() { file,err:=os.Open("water") if err = ...

Posted by imagenesis on Wed, 25 May 2022 23:51:37 +0300

Still processing JSON with map[string]interface {}? Tell you a more efficient method - jsonvalue

This article introduces jsonvalue Library , this is the first multi-functional and comprehensive Go library I developed on Github. At present, it is mainly used in the development of Tencent's future community to replace map[string]interface {}. Why develop this library? Go is a cutting edge in background development. Go engineers will come int ...

Posted by Darhazer on Tue, 24 May 2022 15:58:27 +0300

go micro server startup analysis

Based on go micro version 2.9.1, Example code: example/greeter, git commit:3b3de68cded8879ca3dde5d81192f2881619aabd The core of a microservice server has only three steps service := micro.NewService() service.Init() service.Run() First look at micro NewService() service := micro.NewService( micro.Name("greeter"), micro.Version("latest") ...

Posted by akimm on Tue, 24 May 2022 10:36:22 +0300

Go language programming viper configuration management tool

catalogue Viper Viper is a third-party library of Golang, Github: https://github.com/spf13/viper . It is used to process the configuration information of Golang program. It can process configuration files in various formats. Viper supports the following features: Set default values for configuration items. Load and parse configuration files ...

Posted by tlenker09 on Mon, 23 May 2022 09:39:54 +0300

Error handling in Go multi process concurrent environment

introduction In Go language, we usually use panic and recover to throw and catch errors. This pair of operations has no problem in a single coprocess, but in a multi coprocess, imagine the following two problems. Suppose we now have two processes: If there is A panic in process A, will process B die because of the panic in process A? If A pani ...

Posted by SUNNY ARSLAN on Sat, 21 May 2022 18:14:01 +0300

Eighteen postures for constructing Go application docker image

Cultivation backgroundI worked overtime day and night to develop the simplest Go Hello world application. Although I just quit after printing, my boss also asked me to go online, the only application I can write.The project structure is as follows:. ├── go.mod └── hello.gohello.go code is as follows:package main func main() { println("hell ...

Posted by Jeller on Fri, 20 May 2022 05:47:20 +0300

Golang Time Operation & JSON Serialization and Deserialization

Time operation Time Package Get the current time t := time.Now() fmt.Printf("%T\n", t) //time.Time fmt.Println(t) //2019-07-08 15:23:55.1114609 +0800 DST m=+0.000192401 Gets the specified time t := time.Date(2009, 7, 15, 16, 30, 28, 0, time.Local) fmt.Println(t) //2009-07-15 16:30:28 +0800 DST ...

Posted by dr_overload on Thu, 19 May 2022 20:50:19 +0300

LeetCode algorithm path array part 1

LeetCode algorithm Most bogey, hope to do a series of articles to record the process of brushing algorithm. At present, it is mainly based on LeetCode https://leetcode-cn.com/circle/article/48kq9d/ The module of this post will brush the questions. The content is mainly the summary of the landlord in the post, as well as some personal experience ...

Posted by shak123 on Thu, 19 May 2022 20:46:21 +0300

Go language 10 variable scope

Go language variable scope The scope is the scope of the constant, type, variable, function or package represented by the declared identifier in the source code. Variables in Go language can be declared in three places: Variables defined in a function are called local variables Variables defined outside the function are called global varia ...

Posted by msnhockey on Thu, 19 May 2022 10:35:36 +0300

golang memory management

memory management memory allocator Linear Allocation (Bump Allocator) The pointer points to a free memory address, and the update pointer is modified to allocate the next memory address. Low complexity and high execution efficiencyMemory cannot be reused after being reclaimed Need garbage collection mechanism, mark/copy/generational ...

Posted by kellz on Wed, 18 May 2022 21:45:55 +0300